<Columns>
<Asp: templatecolumn>
<Headertemplate>
<Asp: checkbox id = "chkall"
<B> onclick = "javascript: selectallcheckboxes (this);" </B> runat = "server"
Autopostback = "false" tooltip = "select/deselect all"/>
</Headertemplate>
<Itemtemplate>
<Asp: checkbox id = "chkselect" <B> onclick = "javascript: highlightrow (this);" </B>
Runat = "server" <B> oncheckedchanged = "grdemployees_checkedchanged" </B>
Autopostback = "false"/>
</Itemtemplate>
</ASP: templatecolumn>
</Columns>
// ---------------------------------------------------------------
// select all the checkboxes (Hotmail style)
// -------------------------------------------------------------
function selectallcheckboxes (spanchk) {
// added as aspx uses span for checkbox
var oitem = spanchk. children;
var thebox = oitem. item (0)
xstate = thebox. checked;
Elm = thebox. Form. elements;
For (I = 0; I <Elm. length; I ++)
If (ELM [I]. type = "checkbox" & elm [I]. ID! = Thebox. ID)
{
// Elm [I]. Click ();
If (ELM [I]. Checked! = Xstate)
Elm [I]. Click ();
// Elm [I]. Checked = xstate;
}
}
//-------------------------------------------------------------
// ---- Select highlish rows when the checkboxes are selected
//
// Note: The colors are hardcoded, however you can use
// Registerclientscript Blocks Methods to use Grid's
// Itemtemplates and selecttemplates colors.
// For EX: grdemployees. itemstyle. backcolor or
// Grdemployees. selecteditemstyle. backcolor
//-------------------------------------------------------------
Function highlightrow (chkb ){
VaR oitem = chkb. Children;
Xstate = oitem. Item (0). checked;
If (xstate)
{Chkb. parentelement. parentelement. style. backgroundcolor = 'lightcoral ';
// Grdemployees. selecteditemstyle. backcolor
Chkb. parentelement. parentelement. style. Color = 'white ';
// Grdemployees. selecteditemstyle. forecolor
} Else
{Chkb. parentelement. parentelement. style. backgroundcolor = 'white ';
// Grdemployees. itemstyle. backcolor
Chkb. parentelement. parentelement. style. Color = 'black ';
// Grdemployees. itemstyle. forecolor
}
}
// -->
From http://www.codeproject.com/aspnet/Multi-select_Dataagrid.asp