Reputation:
I have one column which contains value of type TimeSpan
.
What I want to do show the empty cell if TimeSpan
contains the 00:00
value else show as it is?
I tried doing various ways and didn't find any solution so thinking about using the jquery to accomplish this.
Before that wanted to know if it is possible using the DataStringFormat
?
Upvotes: 1
Views: 159
Reputation: 460028
You could use RowDataBound
instead:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int columnIndex = 0; // presuming the first column
String tsText = e.Row.Cells[columnIndex].Text;
TimeSpan ts;
if (!TimeSpan.TryParse(tsText, out ts) || ts == TimeSpan.Zero)
e.Row.Cells[columnIndex].Text = "";
else
e.Row.Cells[columnIndex].Text = ts.ToString();
}
}
Upvotes: 1