GridView Highlight Certain Rows

  • Thread starter Thread starter -Steve-
  • Start date Start date
S

-Steve-

I have the need to change the text of certain rows to red based on the
proximity of a date in one of the columns. What's the best way to go about
this?
 
write code in the rowdaatbound event of the gridview


some like
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
if e.Row.RowType=DataControlRowType.DataRow then
Dim drv As DataRowView = CType(e.Row.DataItem, DataRowView)
if(drv("namecolumnX")="flag1" then
e.row.cssclass="csshighlight"
endif
endif
end sub

hope this works for you

greetings,
Sergio E.
 
I have the need to change the text of certain rows to red based on the
proximity of a date in one of the columns. What's the best way to go about
this?

Add RowDataBound event handler.
Within this handler you can access data though e.Row.DataItem and
GridView row though e.Row.
Something like this:
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
DataRow dataRow = e.Row.DataItem as DataRow;
DateTime dt = dataRow["DataColumn"] as DateTime;
if (...)
e.Row.BackColor = System.Drawing.Color.Red;
}

Regards,
Mykola
http://marss.co.ua
 
Back
Top