Select All GridView CheckBox and gridviewcheckbox
Select All GridView CheckBox
<script type="text/javascript">
$(function () {
$ ("# AllCheck"). click (function () {// click the Select All button
if ($(this).prop("checked")) {
$("#GridView1 :checkbox").prop("checked", true);
} else {
$("#GridView1 :checkbox").prop("checked", false);
}
});
$("#GridView1 :checkbox:gt(0)").click(function () {
var chItem = $("#GridView1 :checkbox:gt(0)");
Var isAllCheck = true; // whether all are selected
for (var i = 0; i < chItem.length; i++) {
if (!$(chItem[i]).prop("checked")) {
isAllCheck = false;
break;
}
}
$("#allCheck").prop("checked", isAllCheck);
});
});
</script>
<asp:GridView ID="GridView1" runat="server" CssClass="dataTable" DataKeyNames="ID">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<input type="checkbox" id="allCheck" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<Asp: TemplateField HeaderText = "operation">
<ItemTemplate>
<A href = "CreateCompanyShop. aspx? Cm = <% # Eval ("COMPANY") %> "title =" details ">
</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
// Obtain the selected ID set
private List<string> GetCheckRowIds()
{
// Obtain the row id selected by the check box
List<string> lst = new List<string>();
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = row.Cells[0].FindControl("CheckBox1") as CheckBox;
if (cb.Checked)
{
lst.Add(GridView1.DataKeys[row.RowIndex].Value.ToString());
//ids += "'" + GridView1.DataKeys[row.RowIndex].Value + "',";
}
}
return lst;
}
public bool DeleteCMShopByIdList(List<string> idList)
{
string ids = string.Empty;
foreach (string item in idList)
{
ids += "'" + item + "',";
}
ids = ids.Trim(',');
string sql = "DELETE Company_Shop WHERE ID IN(" + ids + ");";
SqlTransaction tran = dbhelper.GetTransAction();
try
{
dbhelper.ExcuteNonequery(sql, tran);
tran.Commit();
return true;
}
catch (Exception)
{
tran.Rollback();
}
finally
{
tran.Dispose();
}
return false;
}
//TWO
private string GetCheckRowIds()
{
// Obtain the row id selected by the check box
string ids = string.Empty;
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = row.Cells[0].FindControl("CheckBox1") as CheckBox;
if (cb.Checked)
{
ids += "" + GridView1.DataKeys[row.RowIndex].Value + ",";
}
}
if (ids != string.Empty)
{
ids = ids.TrimEnd(',');
}
return ids;
}
protected void btnSure_Click(object sender, EventArgs e)
{
string ids = GetCheckRowIds();
if (ids == string.Empty)
{
Page. ClientScript. RegisterStartupScript (this. GetType (), "prompt", "<script> alert ('you have not selected any options') </script> ");
return;
}
int undoCount = 0;
string[] idArray = ids.Split(',');
IDbTransaction tran = ConnectStringConfig.GetTran();
try
{
foreach (string id in idArray)
{
string strStatus = "";
string sql = "select ID,TYPE,STATUS from tasks_direct where id = " + id + "";
DataTable dttask = dbHelper.GetDataTable(sql);
foreach (DataRow dr in dttask.Rows)
{
strStatus = dr["STATUS"].ToString();
if (strStatus == "00")
{
boTaskDirect.ConfirmMove(dr["ID"].ToString(), boTaskDirect.TblTaskDirect.WEIGHT.Value, true, tran);
undoCount++;
}
}
}
tran.Commit();
}
catch (Exception ex)
{
tran.Rollback();
Response.Redirect(SysConfig.ErrorPage + ex.Message);
}
finally
{
tran.Dispose();
}
String message = undoCount. ToString () + "task confirmed successfully! ";
Page. ClientScript. RegisterStartupScript (this. GetType (), "prompt", "<script> alert ('" + message + "') </script> ");
Paginationer.BindData();
}
Select All pages in the gridview checkbox
You put a CheckBox at the Header of the column in the CheckBox in the GridView, and it indicates that all are selected (1. the CheckBox below is also checked automatically. 2. If you cancel any of the following checkboxes, the top one will be automatically canceled) and used as a flag for future use.
After dividing the page, the value cannot be obtained through the GridView. You can re-capture the data source based on the mark.
In net, how does one use a checkbox to select all the checkboxes in the gridview?
Protected void oncheckboxtransferchanging (object sender, EventArgs)
{
If (CheckBox1.Checked)
{
CheckBox CheckBox2;
For (int I = 0; I <GridView1.Rows. Count; I ++)
{
CheckBox CheckBox2 = (CheckBox) GridView1.Rows [I]. FindControls ("CheckBox2 ");
If (CheckBox2! = Null)
{
CheckBox2.Checked = false;
}
}
}
}