asp.net GridView控件中模板列CheckBox全选、反选、取消

高洛峰
Lepaskan: 2017-01-11 10:21:07
asal
2637 orang telah melayarinya

using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class Demo18 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == false) { BindData(); } } public void BindData() { string strSql = "select UserID,C_Name,E_Name,UpdataDate,isDY from Demo_User "; DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.CONN_STRING, CommandType.Text, strSql, null).Tables[0]; GridView.DataSource = dt; GridView.DataKeyNames = new string[] { "UserID" };//主键 GridView.DataBind(); } protected void GridView_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView.PageIndex = e.NewPageIndex; BindData(); } protected void Button1_Click(object sender, EventArgs e) { CheckBoxAll.Checked = false; CheckBox1.Checked = false; for (int i = 0; i <= GridView.Rows.Count - 1; i++) { CheckBox CheckBox = (CheckBox)GridView.Rows[i].FindControl("CheckBox"); CheckBox.Checked = false; } } protected void Button2_Click(object sender, EventArgs e) { for (int i = 0; i <= GridView.Rows.Count - 1; i++) { CheckBox CheckBox = (CheckBox)GridView.Rows[i].FindControl("CheckBox"); if (CheckBox.Checked == true) { string strSql = "Update Demo_User set UpdataDate=@UpdataDate where UserID=@UserID "; SqlParameter[] para = { new SqlParameter("@UpdataDate", DateTime.Now), new SqlParameter("@UserID", GridView.DataKeys[i].Value), }; SqlHelper.ExecuteNonQuery(SqlHelper.CONN_STRING, CommandType.Text, strSql, para); } } CheckBoxAll.Checked = false; CheckBox1.Checked = false; BindData(); } protected void CheckBoxAll_CheckedChanged(object sender, EventArgs e) { for (int i = 0; i <= GridView.Rows.Count - 1; i++) { CheckBox CheckBox = (CheckBox)GridView.Rows[i].FindControl("CheckBox"); if (CheckBoxAll.Checked == true) { CheckBox.Checked = true; } else { CheckBox.Checked = false; } } CheckBox1.Checked = false; } protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { for (int i = 0; i <= GridView.Rows.Count - 1; i++) { CheckBox CheckBox = (CheckBox)GridView.Rows[i].FindControl("CheckBox"); if (CheckBox.Checked == false) { CheckBox.Checked = true; } else { CheckBox.Checked = false; } } CheckBoxAll.Checked = false; } } 
GridView演示
Salin selepas log masuk

asp.net GridView控件中模板列CheckBox全选、反选、取消

更多asp.net GridView控件中模板列CheckBox全选、反选、取消相关文章请关注PHP中文网!

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!