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>