【发布时间】:2014-01-30 07:01:04
【问题描述】:
我有两个 GridView。 Gridview1 有数据源。当 CheckBox 被选中时,我想将它们的值传输到 GridView2,但 DataTable 返回 null。
这是我的代码:
public void getSelectRows()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[5] { new DataColumn("Fabric"), new DataColumn("Roll"), new DataColumn("Batch"), new DataColumn("Width"), new DataColumn("Weight") });
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox chkRow = (row.Cells[5].FindControl("chkAdd") as CheckBox);
if (chkRow.Checked)
{
string fab = row.Cells[0].Text;
string roll = row.Cells[1].Text;
string batch = row.Cells[2].Text;
string fabwidth = row.Cells[3].Text;
string weight = row.Cells[4].Text;
dt.Rows.Add(fab, roll, batch, fabwidth, weight);
}
}
}
GridView2.DataSource = dt;
GridView2.DataBind();
}
【问题讨论】:
-
datatable is returning null你的意思是里面没有行?你能告诉我们你的Page_Load事件代码吗? -
没有page_load事件代码,但下面的答案是正确的。 :)
标签: c# asp.net gridview checkbox row