访问选中复选框的网格视图行的数据 [英] Accessing data of grid view row whose check box is checked
本文介绍了访问选中复选框的网格视图行的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在网格视图列中选中了一个复选框。我想访问检查了相应复选框的网格视图行的所有值。
I have taken a check box in a grid view column.I want access all the values of the grid view row whose corresponding check box is checked.
推荐答案
请检查以下网址
http://stackoverflow.com/questions/5737597/getting-checked-rows-from-gridview-in-asp-net [ ^ ]
Pleas check below url
http://stackoverflow.com/questions/5737597/getting-checked-rows-from-gridview-in-asp-net[^]
按照以下代码。它解释了您在按钮单击上所需的操作:
Follow below code.It explains the action required by you on button click:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["yourstring name"].ConnectionString;
conn.Open();
DataTable dtable = new DataTable();
dtable.Columns.Add(new DataColumn("field name", typeof(string)));
//Define datatable based on your requirement
Session["dt"] = dtable;
foreach (GridViewRow gvrow in yourgridview.Rows)
{
CheckBox chk = (CheckBox)gvrow.Cells[3].FindControl("yourcheckbox");//checkbox is in 4th column,hence Cells[3]
if (chk != null && chk.Checked)
{
dtable=(DataTable)Session["dt"];
DataRow dd = dtable.NewRow();
dd["field name"] = (gvrow.Cells[1].Text);//store data appropriately
dtable.Rows.Add(dd);
GridView1.DataSource = dtable;//getting data in another gridview
GridView1.DataBind();
Session["dt"] = dtable;
}
}
}
这篇关于访问选中复选框的网格视图行的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文