Reputation: 179
I have a grid view displaying the messages a user has. Each message the user has is being marked whether it has been read or unread as a bit in my database table.
Is there a way how I can change the style of certain rows in my grid view according to whether the messages are read or unread? I wish to display the whole row with an unread message in bold.
Upvotes: 2
Views: 1872
Reputation: 107950
You will need to use the RowDataBound
event for such a task. Here is an example:
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" >
...
</asp:GridView>
.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
// searching through the rows
if (e.Row.RowType == DataControlRowType.DataRow)
{
bool isnew = (bool)DataBinder.Eval(e.Row.DataItem, "IsNew");
if ( isnew ) e.Row.BackColor = Color.FromName("#FAF7DA"); // is a "new" row
}
}
Reference: http://blog.devexperience.net/en/5/Change_background_color_of_GridView's_Rows.aspx
Upvotes: 6