【发布时间】:2019-06-22 08:36:47
【问题描述】:
我在网格视图列中添加了一个动态创建复选框,但它在按钮单击时给了我空值。
回帖后复选框消失。
这是我的代码
protected void grdreport_RowDataBound(object sender, GridViewRowEventArgs e)
{
int temp = e.Row.Cells.Count;
temp--;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (temp >= 3)
{
strheadertext1 = grdreport.HeaderRow.Cells[3].Text;
CheckBox cb1 = new CheckBox();
cb1.Text = e.Row.Cells[3].Text;
e.Row.Cells[3].Controls.Add(cb1);
}
}
}
然后在我的按钮上单击我检查复选框的值是否被选中
foreach (GridViewRow item in grdreport.Rows)
{
if (item.RowType == DataControlRowType.DataRow)
{
CheckBox checkbox1 = (CheckBox)item.FindControl("cb1");
// cb1.Checked = true;
if (checkbox1.Checked)
{
}
}
}
【问题讨论】:
标签: c# asp.net gridview postback