Asp.net gridview and datalist to move the mouse over the row to change color
Source: Internet
Author: User
In the rowdatabound event of the gridview control, add the following Code
If (E. Row. rowtype = datacontrolrowtype. datarow)
{
// Change the background color when the mouse moves over the line
E. Row. Attributes. Add ("onmouseover", "c = This. style. backgroundcolor; this. style. backgroundcolor = '# ee82ee '");
// Restore the background color when you move the mouse away.
E. Row. Attributes. Add ("onmouseout", "This. style. backgroundcolor = C ");
}
After the datalist control is added to the design page, I bind data through cells when using datalist, so the mouse effect is Source code Page implementation, as shown in the following example
<Asp: datalist id = "datalist1" runat = "server" borderwidth = "1">
<Itemtemplate>
<Tr onmouseover = "This. style. backgroundcolor = '# 8ec26f'" onmouseout = "This. style. backgroundcolor ='' ">
<TD>
<Asp: Label id = "label1" runat = "server" text = '<% # databinder. eval (container, "dataitem. ID ") %> '> </ASP: Label>
</TD>
<TD>
<Asp: Label id = "label2" runat = "server" text = '<% # databinder. eval (container, "dataitem. area ") %> '> </ASP: Label>
</TD>
</Tr>
</Itemtemplate>
<Headertemplate>
Header1 </TD>
<TD> header2
</Headertemplate>
</ASP: datalist>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service