GridView Full selection operation
Copy Code code as follows:
' Columns ' =>array (
Array
' Class ' => ' Ccheckboxcolumn ',
' Header ' => ' All selected ',
' Value ' => ' $data->id ',
' Checked ' => ' true ',
' Htmloptions ' =>array (
' Width ' => ' 30 ',
' Style ' => ' text-align:center ',
),
),
Copy Code code as follows:
<div id= "btn" style= "width:100%; Text-align:right" ><?php echo chtml::ajaxlink (' batch update ', Array (' Link/dels '), Array (
' type ' => ' POST ',
' timeout ' => ') 30000 ',
' data ' => ' js:{ids:jquery (' input[name=\ ' link-grid_c0\[\]\ ']:checked '). Map (function () {return $ (this) . Val (); ). Get ()} ',
' beforesend ' => ' function () {$ (' #btn '). Hide (); $ ("#load"). Show ();} ',
' success ' => ' function ( HTML) {alert (HTML);} ',
' complete ' => ' function () {$ (' #btn '). Show (); $ ("#load"). Hide ();} ',
' error ' => ' fun Ction (a,b,c) {if (b== "timeout") {alert ("More than 30 seconds for this execution, please update in batches!") ");}} ',
);? ></div>
<div id= "Load" style= "display:none; text-align:right width:100%; padding-top:20px" > is updating, Please ......</div>
<script>
var ids=jquery ("Input[name= ' link-grid_c0[] ']:checked" later). Map (function ( ) {return $ (this). val ();});
//alert (ids.length);
</script>
asp.net gridview implementation of the full selection, reverse and delete records
In. aspx
Copy Code code as follows:
<asp:gridview id= "GridView1" runat= "Server" autogeneratecolumns= "False" datakeynames = "Mailid" >
<Columns>
<asp:templatefield >
<ItemTemplate>
<asp:checkbox id= "CheckBox1" runat= "server" AutoPostBack = "true"/>
</ItemTemplate>
</asp:TemplateField>
<asp:boundfield datafield= "formaddress" headertext= "formaddress" sortexpression= "FormAddress"/>
<asp:boundfield datafield= "toaddress" headertext= "toaddress" sortexpression= "toaddress"/>
<asp:boundfield datafield= "title" headertext= "title" sortexpression= "title"/>
<asp:boundfield datafield= "Contents" headertext= "Contents" sortexpression= "Contents"/>
<asp:boundfield datafield= "Times" headertext= "Times" sortexpression= "Times"/>
<asp:checkboxfield datafield= "Readflag" headertext= "Readflag" sortexpression= "Readflag"/>
<asp:checkboxfield datafield= "Upflag" headertext= "Upflag" sortexpression= "Upflag"/>
</Columns>
</asp:GridView>
<asp:button id= "Button1" runat= "Server" text= "Select All" onclick= "Button1_Click"/>
<asp:button id= "Button3" runat= "Server" text= "return" onclick= "Button3_Click"/>
<asp:button id= "Button2" runat= "server" text= "Delete selected items" onclick= "button2_click"/>
. CS
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
Setdatabinder ();
}
BUTTON2.ATTRIBUTES.ADD ("onclick", "Return Confirm" ("Are you sure you want to delete the selected record? ')");
}
protected void Setdatabinder ()
{
String sql = "SELECT * from SendMail";
SqlConnection conn = new SqlConnection (configurationmanager.connectionstrings["studyconnectionstring"). ToString ());
Conn. Open ();
SqlDataAdapter da = new SqlDataAdapter (SQL, conn);
DataSet ds = new DataSet ();
Da. Fill (ds, "table");
GridView1. DataSource =ds. Tables ["Table"];
Gridview1.databind ();
Conn. Close ();
}
<summary>
Select All records
</summary>
<param name= "Sender" ></param>
<param name= "E" ></param>
protected void Button1_Click (object sender, EventArgs e)
{
CheckBox CB;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CB = (CheckBox) gridview1.rows[i]. Cells[0]. FindControl ("CheckBox1");
Cb. Checked = true;
}
}
<summary>
Deletes the selected item by performing a delete operation
</summary>
<param name= "Sender" ></param>
<param name= "E" ></param>
protected void button2_click (object sender, EventArgs e)
{
String sql= "(";
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox cb = (checkbox) Gridview1.rows[i]. FindControl ("CheckBox1");
if (CB). Checked = = True)
{
sql = SQL + convert.toint32 (gridview1.datakeys[i]. Value) + ",";
}
}
Remove the last comma and add the right-hand number
sql = SQL. Substring (0,sql. Length-1) + ")";
sql = "Delete SendMail where mailid in" +SQL;
SqlConnection conn = new SqlConnection (configurationmanager.connectionstrings["studyconnectionstring"). ToString ());
Conn. Open ();
Try
{
Execute DELETE statement
SqlCommand cmd = new SqlCommand (SQL, conn);
int delcount = Convert.ToInt32 (cmd. ExecuteNonQuery ());
Response.Write ("<script>alert (' delete" + delcount + "data ');</script>");
Setdatabinder ();
}
catch (Exception ex)
{
Response.Write (ex. message);
}
Finally
{
Conn. Close ();
}
}
<summary>
Anti-select operation
</summary>
<param name= "Sender" ></param>
<param name= "E" ></param>
protected void Button3_Click (object sender, EventArgs e)
{
CheckBox CB;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CB = (CheckBox) gridview1.rows[i]. Cells[0]. FindControl ("CheckBox1");
if (CB). Checked)
{
Cb. Checked = false;
}
Else
{
Cb. Checked = true;
}
}
}