Full select/cancel all select control (checkbox) of the DataGrid)

Source: Internet
Author: User

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 ();
}
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.