Write a common JS Function
Code
Function Gridviewcolor (gridviewid ){
// Obtain all rows to be controlled
VaR Allrows = Document. getelementbyid (gridviewid );
If (Allrows ! = Null ){
Allrows = Allrows. getelementsbytagname ( " Tr " );
// Set the background color and events of each row. The cycle starts from 1 instead of 0. You can avoid the row in the header.
For ( VaR I = 1 ; I < Allrows. length; I ++ ){
Allrows [I]. onmouseout = Function (){ This . Style. Background = " # Ffffff " ;}
}
}
}
To reference this JavaScript code, you only need to register it in page_load on each page. ctl00_pagebody_gvitems is the Client ID of girdview.
Scriptmanager. registerstartupscript (This. Page,This. GetType (),"JS","Gridviewcolor ('ctl00 _ pagebody_gvitems ');",True);
All selectedCode:
< Script Type = "Text/JavaScript" >
Function Checkall (ocheckbox)
{
VaR Gvitems = Document. getelementbyid ( " <% = Gvitems. clientid %> " );
For (I = 1 ; I < Gvitems. Rows. length; I ++ )
{
Gvitems. Rows [I]. cells [ 0 ]. Getelementsbytagname ( " Input " )[ 0 ]. Checked = Ocheckbox. checked;
}
}
</ Script >
< ASP: gridview ID = "Gvitems" Runat = "Server" > < Columns >
< ASP: templatefield Headertext = "Option" >
< Headertemplate >
< ASP: checkbox ID = "Checkbox1" Runat = "Server" Text = "Select all" Autopostback = "True" Onclick = "Checkall (this )" />
</ Headertemplate > < Itemtemplate >
< ASP: checkbox ID = "Rbtnname" Runat = "Server" CID = '<% # Eval ("candidatesid") % > '
Oncheckedchanged = "rbtnname_checkedchanged"/>
</ Itemtemplate >
</ ASP: templatefield >
</ Columns >
</ ASP: gridview >