简体   繁体   English

如何将GridView中的记录标记为已读和未读

[英]How to mark records in gridview as read and unread

在此处输入图片说明

This is my GridView1. 这是我的GridView1。 I want the latest record to be highlighted and after user click the authorization no(which user viewed the record in next page), the row will not be highlighted (means after the user view the record, the row is back to normal, no highlight no bold font). 我希望突出显示最新记录,并在用户单击授权号(该用户查看了下一页中的记录)后,该行将不突出显示(表示用户查看记录后,该行恢复正常,不突出显示)没有粗体)。

My current progress is, I have created new bit field in my database named ReadStatus, and defaulted to 0 Next, I need to do the onrowdatabound coding in order to implement this. 我当前的进展是,我在数据库中创建了一个名为ReadStatus的新位字段,默认值为0。接下来,我需要执行onrowdatabound编码才能实现这一点。

first question is, do i need to read the bit column(ReadStatus) as I read all this column?AuthorizationNo, ProductID,Name,Qty,---(ReadStatus)?? 第一个问题是,我在读取所有列时是否需要读取位列(ReadStatus)?AuthorizationNo,ProductID,Name,Qty,---(ReadStatus)? should I read ReadStatus in this code? 我应该在这段代码中阅读ReadStatus吗?

           / /READING RECORD FROM TABLE TRACK_ITEM
            while (reader.Read())
            {
                MerchantProduct merchantProduct = new MerchantProduct();
                merchantProduct.TxID = reader["TxID"].ToString();
                merchantProduct.ProductID = reader["ProductID"].ToString();
                merchantProduct.Name = reader["ProductName"].ToString();
                merchantProduct.Qty = Convert.ToInt32(reader["Qty"]);

                listLatestProduct.Add(merchantProduct);
            }
            return listLatestProduct;

second is, can anyone show me the proper way to code in onrowdatabound? 其次,有人可以向我展示在onrowdatabound中进行编码的正确方法吗?

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
           //Tried many code here but none is working 
    }

Thank you. 谢谢。

First you need to add one more column in ur db for ReadStatus(1/0), then make is as hiddenfield in your aspx page. 首先,您需要在ur db中为ReadStatus(1/0)添加一列,然后在aspx页中将make作为hiddenfield。

               <asp:TemplateField HeaderText="ReadStatus" Visible="false">
                                              <ItemTemplate>
                                                      <asp:Label ID="readStatus" runat="server"></asp:Label>
                                                      <asp:HiddenField ID="readStatusHiddenField" runat="server" Value='<%#Eval("ReadStatus") %>'/>
                                                  </ItemTemplate>
                                              </asp:TemplateField>

In your grid rowdataboun, just paste this code.It works for me 在您的网格rowdataboun中,只需粘贴以下代码即可。

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    // searching through the rows
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        int reading = Convert.ToInt32(((HiddenField)e.Row.FindControl("readStatusHiddenField")).Value);
        if (reading == 0)
        {
            e.Row.BackColor = Color.LightGray;
            e.Row.Font.Bold = true;
        }
    }
}

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

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