【问题标题】:Highlighting Row in GridView after postback?回发后在GridView中突出显示行?
【发布时间】:2010-09-28 13:46:06
【问题描述】:

我在我的主gridview中有两个gridviews 1)master和2)detail,其中有几列和一个超链接,所以当用户单击超链接(主gridview)时,我希望该行突出显示,但下面的代码没有回发后保持突出显示的行,即使在回发后,我如何确保其突出显示?

protected void gvReport_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#C2D69B'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");
                e.Row.Attributes.Add("style", "cursor:pointer;");
                //e.Row.Attributes.Add("onclick", "location='patron_detail.aspx?id=" + e.Row.Cells[0].Text + "'");
            } 

    } 

<asp:GridView runat="server" ID="gvReport" AutoGenerateColumns="False" CssClass="gv"
                        DataSourceID="LDS_POReport" Width="880px" AllowPaging="true" AllowSorting="true"
                        OnRowCreated="gvReport_RowCreated" OnRowDataBound="gvReport_RowDataBound" DataKeyNames="Id" PageSize="15">
                        <PagerStyle HorizontalAlign="Left" CssClass='header' BackColor="#E5EAF3" ForeColor="Black" />
                        <PagerSettings Mode="NumericFirstLast" />
                        <EmptyDataTemplate>
                            No Items</EmptyDataTemplate>
                        <Columns> 
                            <asp:TemplateField HeaderText="Name" SortExpression="Name">
                                <ItemTemplate>
                                    &nbsp;
                                    <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Number Of Items" SortExpression="NumberOfItems">
                                <ItemTemplate>
                                    <a href='Officer.aspx?Id=<%# Eval("Id") %>'>
                                        <%# Eval("NumberOfItem")%>
                                    </a>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>

【问题讨论】:

    标签: asp.net gridview


    【解决方案1】:

    抱歉问题...您确定要检查 2 个整数值吗?...如果是... 在您拥有的 html 中,表格的 TD 元素中是否有背景颜色?如果html代码中有颜色代码,可能是css样式定义的问题。

    【讨论】:

      【解决方案2】:

      只需在查询字符串中放一个行索引,回发后读取,然后根据索引选择行并更改颜色。

      【讨论】:

      • 我在查询字符串中有索引,您在回发后在哪里阅读它?并选择行?
      • 在 gvRowDataBound 中设置。 if(Request.QueryString["rowindex"] == e.Row.RowIndex) { //设置行背景样式 }
      • 即使我得到了匹配的 id (querystring & e.row.rowindex) 并且当页面回发时它不保留背景色
      • 您是否设置了断点以实时查看值的比较情况?另外,我的原始示例可能不是很好,因为 querystring 会返回一个...字符串...将 .ToString() 添加到 e.Row.RowIndex。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-16
      • 1970-01-01
      • 2018-06-05
      • 2011-02-21
      • 2010-10-03
      • 1970-01-01
      相关资源
      最近更新 更多