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"); } }
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索listview
, item
, backgroundcolor
, findcontrol
, style
Attributes
,以便于您获取更多的相关知识。
时间: 2024-07-31 15:53:00