First of all, we must first make a data GridView.
After the GridView is ready, we add a TemplateField to the backend)
Add a CheckBox to the HeaderTemplate in the newly added template bit for full selection, and then add a CheckBox to the ItemTemplate.
Copy codeThe Code is as follows:
<Asp: TemplateField>
<HeaderTemplate>
<Asp: CheckBox ID = "CheckAll" runat = "server" onclick = "SelectAllCheckboxes (this);" Text = "select all/cancel" ToolTip = "select all at once, cancel the entire selection once again "/>
</HeaderTemplate>
<ItemTemplate>
<Asp: CheckBox ID = "CheckBox2" runat = "server" Text = "select all"/>
</ItemTemplate>
</Asp: TemplateField>
Add the following Java Script at the bottom of the Script
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function SelectAllCheckboxes (spanChk)
{
Elm = document. forms [0];
For (I = 0; I <elm. length; I ++)
{
If (elm [I]. type = "checkbox" & elm [I]. id! = SpanChk. id)
{
If (elm. elements [I]. checked! = SpanChk. checked)
Elm. elements [I]. click ();
}
}
}
</Script>
If MasterPage is applied to your webpage, place the above JS file on the </asp: Content> standard homepage, now you have completed the entire selection and canceled the entire selection function, next, we want to modify some of the changes (you will never make a full selection/cancellation function, just to make the user fun ), next, place a Button on the Response surface, and switch the cursor to the program section under the two push points, after the code is switched to the program part, we use the following code to capture which columns (ROW) are checked.
Copy codeThe Code is as follows:
Int I;
For (I = 0; I <this. GridView1.Rows. Count; I ++)
{
If (CheckBox) GridView1.Rows [I]. FindControl ("CheckBox2"). Checked)
{
Response. Write (GridView1.DataKeys [I]. Value. ToString ());
// GridView1.DataKeys [I]. Value. ToString () can capture the Value of DataKeys in this column. I set the Value of pk.
}
}
If your GridVie has not set DataKeyNames = "resource bit", the code above will not list the pkvalue values.
With the above method, you can check which columns have been checked by users for other programs that you want to renew.