Monday, 13 August 2007

Highlighting Row in GridView

I recently had a situation where I had to highlight a row in the gridview if the value of the column Today was 0. Found out there was a very easy way to do it using the OnRowDataBound Event of the GridView, the code's below..

protected void GridViewID_OnRowDataBound(object sender, GridViewRowEventArgs e)
GridViewRow row = e.Row;
if (row.RowType == DataControlRowType.DataRow)
DataRowView drv = row.DataItem as DataRowView;
string fieldName= drv["FIELDNAME"].ToString();
if (fieldName.Equals("0"))
row.CssClass = "YourCssClassName";

No comments: