DataGrid code:
<Form ID = "form1" method = "Post" runat = "server">
<Asp: textbox id = "textbox1" style = "Z-INDEX: 101; left: 448px; position: absolute; top: 296px"
Runat = "server"> </ASP: textbox>
<Asp: DataGrid id = "datagrid1" style = "Z-INDEX: 102; left: 88px; position: absolute; top: 48px" runat = "server"
Bordercolor = "#999999" borderstyle = "NONE" borderwidth = "1px" backcolor = "white" cellpadding = "3"
Gridlines = "vertical">
<Footerstyle forecolor = "black" backcolor = "# cccccc"> </footerstyle>
<Selecteditemstyle font-bold = "true" forecolor = "white" backcolor = "# 008a8c"> </selecteditemstyle>
<Alternatingitemstyle backcolor = "gainsboro"> </alternatingitemstyle>
<Itemstyle forecolor = "black" backcolor = "# eeeeee"> </itemstyle>
<Headerstyle font-bold = "true" forecolor = "white" backcolor = "#000084"> <Columns>
<Asp: templatecolumn>
<Headertemplate>
<Input id = "checkall" name = "checkall" onclick = "chooseall ()" type = "checkbox">
</Headertemplate>
<Itemtemplate>
<Asp: checkbox id = "checkbox1" runat = "server"> </ASP: checkbox>
</Itemtemplate>
<Headerstyle wrap = "false"> </ASP: templatecolumn>
</Columns>
<Pagerstyle horizontalalign = "center" forecolor = "black" backcolor = "#999999" mode = "numericpages"> </pagerstyle>
</ASP: DataGrid>
</Form>
JavaScript code:
<Script language = "JavaScript">
VaR checkflag = true;
Function chooseall ()
{
// Alert (checkflag );
If (checkflag)
{
VaR inputs = Document. All. Tags ("input ");
Alert (inputs. Length );
For (VAR I = 0; I <inputs. length; I ++)
{
If (inputs [I]. type = "checkbox" & inputs [I]. ID! = "Checkall ")
{
Inputs [I]. Checked = true;
}
}
Checkflag = false;
}
Else
{
VaR inputs = Document. All. Tags ("input ");
For (VAR I = 0; I <inputs. length; I ++)
{
If (inputs [I]. type = "checkbox" & inputs [I]. ID! = "Checkall ")
{
Inputs [I]. Checked = false;
}
}
Checkflag = true;
}
}
</SCRIPT>
Confirm deletion:
// <Summary>
// Ask the user to confirm and delete the data.
/// </Summary>
Function delrec ()
{
VaR inputs = Document. All. Tags ("input ");
VaR selectedlen = 0;
For (VAR I = 0; I <inputs. length; I ++)
{
If (inputs [I]. type = "checkbox ")
{
If (inputs [I]. Checked)
{
If (inputs [I]. ID! = "Checkall ")
{
Selectedlen ++;
}
}
}
}
If (selectedlen = 0)
{
Alert ("select the data you want to delete first! ");
}
Else
{
VaR flag = confirm ("are you sure you want to delete the selected" + selectedlen + "data? ");
If (FLAG)
{
Document. All ("btndelrecord"). Click ();
}
}
}
Note the case sensitivity, which is difficult to debug with javasript, so be sure to note the case sensitivity.