binding gridview
-
Hi i bind a gridview and one of the column show the data this form "aaa#;7" i want show just "aaa", how can i remove "#;7" from the end of data in gridview column when it bindings. Thnaks
Hi, You need to add a RowDataBound to your GridView. Then, in the GridView_RowDataBound(object sender, GridViewRowEventArgs e) method, you'll be able to access e which will provide you with access to the individual cells of that row where you can specify a formatter. Example :
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRowEventArgs ea = e as GridViewRowEventArgs;
if (ea.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drv = e.Row.DataItem as DataRowView;
Object ob = drv["Phone"];
if (!Convert.IsDBNull(ob))
{
Int64 iParsedValue = 0;
if (Int64.TryParse(ob.ToString(), out iParsedValue))
{
TableCell cell = ea.Row.Cells[4];
cell.Text = String.Format(System.Globalization.CultureInfo.CurrentCulture,
"{0:(###) ###-####}", new object[] { iParsedValue });
}
}
}
}Light or darkness, we must choose ...