Thursday, January 22, 2009

To create Dynamic DataTable and display in GridView

Hi,
We can create DataTable dynamically and display the content either in GridView or DataList or in Repeater.


DataTable dataTable = new DataTable();
DataRow dataRow;
dataTable.Columns.Add(new DataColumn("Title", typeof(string)));
dataTable.Columns.Add(new DataColumn("Description", typeof(string)));
dataTable.Columns.Add(new DataColumn("Author", typeof(string)));
if (_post != null)
{
dataRow = dataTable.NewRow();
dataRow[0] = _post.Title;
dataRow[1] = _post.Description;
dataRow[2] = _user.DisplayName;
dataTable.Rows.Add(dataRow);
}

myDataList.DataSource = dataTable;
myDataList.DataBind();

Wednesday, January 21, 2009

To Convert HTML Text to Normal Text

Hi,

If you want to remove the html tag from the text and replace as normal text use the following coding in Javascript.
using
System.Text.RegularExpressions;

private string StripTags(string HTML)
{
// Removes tags from passed HTML
Regex objRegEx = new Regex("<[^>]*>");
return objRegEx.Replace(HTML, "");
}