简体   繁体   中英

C#: GridView, Row-By-Row Operations

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM