基于GridView外部的文本框值的Gridview行颜色

时间:2018-08-08 10:35:11

标签: c# asp.net gridview

我想更改Gridview行的背景颜色。情况是我想更改BoundField Id等于Gridview外部文本框中显示的值的特定行的背景颜色。我能够使用RowDataBound以及在!IsPostBack和页面加载中也能实现,但是问题是颜色只是闪烁(在几分之一毫秒内迅速消失)而没有停留(无法保持)。我看过其他可用的类似示例,但它不符合我的情况,因此请不要将其标记为重复。

下面是我的Gridview:

<asp:GridView ID="gvProduct" runat="server" AutoGenerateColumns="false" OnRowDataBound="gvCustomers_RowDataBound">
                                    <Columns>
                                        <asp:HyperLinkField HeaderStyle-Width="150px" DataTextField="AssetsName" HeaderText="Product" />
                                        <asp:BoundField HeaderStyle-Width="150px" DataField="InventorySubName" HeaderText="Inventory"
                                            ItemStyle-CssClass="" />
                                        <asp:BoundField HeaderStyle-Width="50px" DataField="Id" HeaderText="Id" Visible="true"
                                            ItemStyle-CssClass="" />
                                    </Columns>
                                </asp:GridView>

后面的代码:

protected void gvProduct_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        foreach (GridViewRow row in gvProduct.Rows)
        {
            if (row.Cells[2].Text.Equals(txt_AId1.Text)) //txt_AId1.Text is retrieved during pageload from url string
            {
                row.BackColor = System.Drawing.Color.Red;
                row.ForeColor = System.Drawing.Color.White;
            }
        }
    }

0 个答案:

没有答案
相关问题