简体   繁体   English

C#:GridView,逐行操作

[英]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. 您将需要将RowDataBound事件用于此类任务。 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 参考: http : //blog.devexperience.net/en/5/Change_background_color_of_GridView's_Rows.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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