[ASP.NET]GridView里的 checkbox 怎么做(template)

目标:捞值到grid,再读取打勾的row
http://img2.58codes.com/2024/20106764gb9nn0Jrf3.png

add GridView
新增checkbox 转成template
http://img2.58codes.com/2024/20106764aORh59794n.png

塞资料

 protected void BtnQry_Click(object sender, EventArgs e)        {            System.Data.DataTable dt = new System.Data.DataTable();            dt.Columns.Add("t1");            dt.Columns.Add("t2");            dt.Columns.Add("t3");            dt.Rows.Add();            dt.Rows[0][0] = "test0";            dt.Rows[0][1] = "test1";            dt.Rows[0][2] = "test2";            dt.Rows.Add();            dt.Rows[1][0] = "test10";            dt.Rows[1][1] = "test11";            dt.Rows[1][2] = "test12";            GridView1.DataSource = dt;            GridView1.DataBind();        }

读读看

        protected void BtnSave_Click(object sender, EventArgs e)        {            string xx = "";                       for (int i = 0; i < GridView1.Rows.Count; i++)            {                 CheckBox cb  = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); ;//拿check                if (cb.Checked)                {                                    xx = GridView1.Rows[i].Cells[1].Text;//拿cell里的值                    Response.Write(i.ToString()+xx+"--");                }            }        }

试一下设定chekbox

        protected void BtnSelAll_Click(object sender, EventArgs e)        {            for (int i = 0; i < GridView1.Rows.Count; i++)            {                CheckBox cb = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); ;                 cb.Checked = true;                                            }         }        protected void BtnCancelSelAll_Click(object sender, EventArgs e)        {            for (int i = 0; i < GridView1.Rows.Count; i++)            {                CheckBox cb = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); ;                cb.Checked = false;            }        }

关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章