1、鼠標移到ListView某一行時改變該行的背景色方法
前端代碼:
<asp:ListView ID="ListView1" runat="server" onitemdatabound="ListView1_ItemDataBound"> <LayoutTemplate> <table id="Table1" runat="server" border="0" style=""> <tr runat="server" id="itemPlaceholder" /> </table> </LayoutTemplate> <ItemTemplate> <tr runat="server" id="Tr"> <td> <%#Eval("ID") %> </td> <td> <%# Eval("name") %> </td> <td> <%# Eval("age") %> </td> </tr> </ItemTemplate> </asp:ListView>
後台代碼:
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e) { if (e.Item.ItemType==ListViewItemType.DataItem) { (e.Item.FindControl("Tr") as HtmlTableRow).Attributes. Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'"); (e.Item.FindControl("Tr") as HtmlTableRow).Attributes. Add("onmouseout", "this.style.backgroundColor=c"); } }