Highlight button if field is not null C#
I was hoping someone could share some code relative to "flagging" rows in a gridview. The first column of my gv is a column of buttons that bring up a new window based on the item listed in that row.
I would like to highlight the button (or the row in some other way) if one of two conditions (or both) is true.
The window pop-up that opens with the button click shows a small gv if data exists as well as a Comments formview. So I would highlight if that gv appears (meaning the data exists--query for this is already written) or if the Comments field is not null.
Littl开发者_如何学运维e tricky since the two conditions work off different SPs and different source tables, but getting a highlight for at least one would still be a huge step.
Thank you so much for your help!
You can do it in the RowDataBound
event of the Gridview. If a certain condition is met, then you can change the color of that row to distinguish it from other rows. For example:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRow dr = ((DataRowView)e.Row.DataItem).Row;
if(dr["ColumnName"] && dr["ColumnName1"])
{
e.Row.Style.Add("Color", "Red");
}
}
}
精彩评论