Add colors and events in the gridview row

Source: Internet
Author: User

In the gridview list, you need to add the following effects. If the color changes, the original color is removed. In the row selection, you need to deepen the color to know which row is selected, in particular, when the list data is large, the flag is very important and the selected row event is triggered. How can we add colors to the row selection and set the event as well? If we bind e. Row. Attributes. Add ("onclick" twice, we find that only one of them can be triggered. In fact, we can put the other into one.

The following is an example:
Copy codeThe Code is as follows:
Protected void EditGridview_RowDataBound (object sender, GridViewRowEventArgs e)
{
If (e. Row. RowType = DataControlRowType. DataRow)
{
// 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 = 'activecaptiontext', this. style. fontWeight = ''; this. style. cursor = 'hand ';");
// Restore the background color when the mouse leaves
E. Row. Attributes. Add ("onmouseout", "this. style. backgroundColor = currentcolor, this. style. fontWeight = '';");
// Deepen the color when the mouse clicks
E. Row. Attributes. Add ("onclick", "setvalue (); if (window. oldtr! Extends null1_1_1_oldtr.runtimestyle.csstext}''{%this.runtimestyle.css Text = 'background-color: # e6c5fc '; window. oldtr = this ");

}


}

Js Code:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function setvalue (){
Alert ('row-Click Event and color-changing simultaneously ');
}
</Script>

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.