我是asp.net开发人员中的新手。
借助数据表填充了一个asp.net网格视图,my列是动态的。现在,我想在我的所有列中添加一个复选框,动态bot不想添加行。有一次,我只能选中一个复选box.If,我正在选择第二次复选框,在这种情况下,首先选中的复选框应该取消选中。
我的代码如下:
protected void dgvWoList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
if (e.Row.Cells[i] != null && (!e.Row.Cells[i].IsNullOrEmpty()))
{
CheckBox chk = new CheckBox();
chk.Text = e.Row.Cells[i].Text;
e.Row.Cells[i].Controls.Add(chk);
}
}
}
}
现在,我试图取消复选框,但无法做到。请帮帮我。
答:非常感谢你的回答。感谢AnthonyBCodes的建议,而不是复选框,使用单选按钮解决了我的问题。我将代码从复选框更改为单选按钮,如下所示。
RadioButton chk = new RadioButton();
chk.GroupName = "radio";
chk.Text = e.Row.Cells[i].Text;
e.Row.Cells[i].Controls.Add(chk);
发布于 2015-01-27 01:47:12
(在评论中得到答复,并由执行部分对问题进行编辑。移动到社区wiki回答。见Question with no answers, but issue solved in the comments (or extended in chat) )
“任择议定书”写道:
非常感谢你的回答。特别感谢@AnthonyBCodes您的建议,而不是复选框,使用单选按钮解决我的问题。我将代码从复选框更改为单选按钮,如下所示。
RadioButton chk = new RadioButton();
chk.GroupName = "radio";
chk.Text = e.Row.Cells[i].Text;
e.Row.Cells[i].Controls.Add(chk);
https://stackoverflow.com/questions/21127480
复制相似问题