Asp.net 回发后在GridView中高亮显示行?
我的主gridview中有两个gridview 1)主视图和2)详细视图,其中只有几列和一个超链接,因此当用户单击超链接(主gridview)时,我希望该行高亮显示,但下面的代码在它进行回发后不会保留高亮显示的行,如何确保即使在它进行回发后也能高亮显示Asp.net 回发后在GridView中高亮显示行?,asp.net,gridview,Asp.net,Gridview,我的主gridview中有两个gridview 1)主视图和2)详细视图,其中只有几列和一个超链接,因此当用户单击超链接(主gridview)时,我希望该行高亮显示,但下面的代码在它进行回发后不会保留高亮显示的行,如何确保即使在它进行回发后也能高亮显示 protected void gvReport_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == Dat
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>
<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>
protectedvoid gvReport\u RowDataBound(对象发送方,GridViewRowEventArgs e)
{
如果(e.Row.RowType==DataControlRowType.DataRow)
{
e、 添加(“onmouseover”,“this.style.backgroundColor=”#C2D69B');
e、 添加(“onmouseout”,“this.style.backgroundColor='white'”);
e、 添加(“样式”,“光标:指针;”);
//e、 添加(“onclick”,“location='patron\u detail.aspx?id=“+e.Row.Cells[0].Text+””);
}
}
只需在查询字符串中放置一行索引,并在回发后读取,然后根据索引选择行并更改颜色。很抱歉提出这个问题。。。您确定要在两个整数值之间进行检查吗?。。。如果是的话。。。
在html中,表的TD元素中有背景色吗?如果html代码中有颜色代码,可能是css样式定义的问题。我在查询字符串中有索引,回发后在哪里阅读?然后选择行?在GVROWDABOUND中设置它。如果(Request.QueryString[“rowindex”]==e.Row.rowindex){//set Row background style}即使我获得了匹配的id(QueryString&e.Row.rowindex),并且当页面回发时它没有保留BackColor,您是否设置了断点以查看值如何实时比较?另外,我的原始示例可能不太好,因为querystring将返回一个…字符串。。。将.ToString()添加到e.Row.RowIndex。