我的asp.net程序中有一个gridview参数,如下所示:
姓名:row.Cells[5].Controls[0]
价值:(Text="" Checked=true)
输入:System.Web.UI.WebControls.CheckBox
如何获取此类参数的Checked状态?
答案 0 :(得分:0)
自从我使用GridView以来已经有一段时间了。你试过这个吗?
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { var mycheckbox = (CheckBox)e.Row.Cells[5].Controls[0]; var status = mycheckbox.checked; }
答案 1 :(得分:0)
下面...
(CType(gridview.Rows(0).Cells(5).Controls(0), CheckBox).Checked)
答案 2 :(得分:0)
如果您为该控件指定了id,那么您可以使用FindControl
方法,否则您可以继续使用Controls [0]。无论如何你必须尝试这样的事情:
CheckBox chkBox = row.Cells[5].FindControl("checkBoxId") as CheckBox;
if (chkBox.Checked)
{
// given checkbox is checked
}
else
{
// it is not checked
}
或者像这样:
CheckBox chkBox = row.Cells[5].Controls[0] as CheckBox;
if (chkBox.Checked)
{
// given checkbox is checked
}
else
{
// it is not checked
}