使用更新面板更新gridview后会出现此问题
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GridView1" CssClass="GridGis" runat="server" AutoGenerateColumns="False" PageSize="5" OnPageIndexChanging="GridView1_PageIndexChanging" AllowPaging="True" >
<Columns>
<asp:BoundField DataField="nome" HeaderText="Nome" />
<asp:BoundField DataField="idade" HeaderText="Idade" />
<asp:BoundField DataField="cidade" HeaderText="Cidade" />
<asp:BoundField DataField="uf" HeaderText="UF" />
<asp:BoundField DataField="datanasc" HeaderText="Data/Nascimento" DataFormatString="{0:dd/MM/yyyy}" />
<asp:BoundField DataField="salario" HeaderText="Salário" />
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button4" EventName="Click" />
</Triggers>
</asp:UpdatePanel>`
答案 0 :(得分:0)
UpdatePanel刷新时,您正在丢失事件处理程序。我的建议是使用事件委托,这样你就不必担心重新绑定了:
$(document).on('mouseenter', '#GridView1 tr', function() {
$(this).css({ "background-color": "lightgreen", "cursor": "pointer" });
}).on('mouseleave', '#GridView1 tr', function() {
$(this).css({ "background-color": "white" });
});
如果你能找到一个比GridView
更接近document
的祖先,但仍然在UpdatePanel
之外,那将是理想的。
或者,这个简单的东西可能更好用纯css解决:
#GridView1 tr {
background-color:white;
cursor:pointer;
}
#GridView1 tr:hover {
background-color:lightgreen;
}