Hover the mouse color in the asp.net Gridview data column

Source: Internet
Author: User

Function Description:
In the gridview, when the mouse moves in the data list of this control, the background of this column changes the background color as the mouse moves.
Function implementation:
Add an event RowDataBound in the gridview. The Code is as follows:
Copy codeThe Code is as follows:
Protected void gvwNews_RowDataBound (object sender, GridViewRowEventArgs e)
{
If (e. Row. RowType = DataControlRowType. DataRow)
{
E. Row. Attributes. Add ("onmouseover", "color = this. style. backgroundColor; this. style. backgroundColor = '# EAFCD5 '");
E. Row. Attributes. Add ("onmouseout", "this. style. backgroundColor = color ");
E. Row. Attributes. Add ("onclick", "ClickRow ()");
}
}

The onclick event controls the check box at the beginning of a row. Click the row to achieve the same effect as the "click" check box. The Code is as follows:
Copy codeThe Code is as follows:
Function ClickRow ()
{
Var obj = event. srcElement. parentElement. firstChild. firstChild. tagName;
Alert (obj );
If (obj! = Null & obj. tagName + ""! = "Undefined ")
{
Obj. checked = obj. checked? False: true;
}
}

A few simple lines of code are required.

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.