DataGrid Control:
<Columns>
<Asp: templatecolumn>
<Headerstyle width = "10px"> <Headertemplate>
<Input id = "checkall" name = "checkall" type = "checkbox" onclick = "chooseall ()">
</Headertemplate>
<Itemtemplate>
<Asp: checkbox id = "checkbox1" runat = "server"> </ASP: checkbox>
</Itemtemplate>
</ASP: templatecolumn>
<Asp: templatecolumn headertext = "no.">
<Headerstyle wrap = "false"> <Itemtemplate>
<Asp: Label runat = "server" id = "labno"> </ASP: Label>
</Itemtemplate>
</ASP: templatecolumn>
JavaScript Functions:
VaR checkflag = true;
Function chooseall ()
{
// If (! Document. All ("checkall"). Checked) // select all
If (checkflag) // select all
{
VaR inputs = Document. All. Tags ("input ");
For (VAR I = 0; I <inputs. length; I ++) // traverses all input values on the page
{
If (inputs [I]. type = "checkbox" & inputs [I]. ID! = "Checkall ")
{
Inputs [I]. Checked = true;
}
}
Checkflag = false;
}
Else // cancel all selections
{
VaR inputs = Document. All. Tags ("input ");
For (VAR I = 0; I <inputs. length; I ++) // traverses all input values on the page
{
If (inputs [I]. type = "checkbox" & inputs [I]. ID! = "Checkall ")
{
Inputs [I]. Checked = false;
}
}
Checkflag = true;
}
}
// <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 ();
}
}
}