In ASP. net2.0, add the row color highlighted by the mouse over (onmouseover, onmouseout) to the gridview!

Source: Internet
Author: User
Protected void gridview1_rowdatabound (Object sender, gridviewroweventargs E)
{
// Mark rows meeting specific conditions as highlighted
If (E. Row. rowtype = datacontrolrowtype. datarow) // determines whether the current row belongs to the datarow type.
{
Int money = convert. toint32 (databinder. eval (E. Row. dataitem, "money"); // obtain the column value of the current row
If (money = 77)
E. Row. backcolor = color. Red;
// String customer = (string) databinder. eval (E. Row. dataitem, "customer ");
String customer = databinder. eval (E. Row. dataitem, "customer"). tostring ();
If (customer = "SDF ")
E. Row. backcolor = color. Red;
}
// Add the highlighted effect of mouse sliding
If (E. Row. rowtype = datacontrolrowtype. datarow) // determines whether the current row belongs to the datarow type.
{
// Save the background color of the current row and add a color when you move the cursor over it.
E. row. attributes. add ("onmouseover", "currentcolor = This. style. backgroundcolor; this. style. backgroundcolor = 'yellow', this. style. fontweight = '';");
// Restore the background color when the mouse leaves
E. Row. Attributes. Add ("onmouseout", "This. style. backgroundcolor = currentcolor, this. style. fontweight = '';");
}
// Click a row to change the background color of the row.
If (E. Row. rowtype = datacontrolrowtype. datarow)
{
E. row. attributes. add ("onclick", "this. style. backgroundcolor = '# 99cc00'; this. style. color = 'buttontext'; this. style. cursor = 'default ';");
}

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.