Asp.net GridView and DataList to move the mouse over the row to change color

Source: Internet
Author: User

Add the following code to the RowDataBound event of the GridView control:
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 implemented on the source code page, 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>

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.