【问题标题】:How can I get the checked status of a checkbox如何获取复选框的选中状态
【发布时间】:2017-03-29 02:57:58
【问题描述】:

我的asp.net程序中有一个gridview参数如下:

姓名:row.Cells[5].Controls[0]

值:(Text="" Checked=true)

输入:System.Web.UI.WebControls.CheckBox

如何获取此类参数的 Checked 状态?

【问题讨论】:

    标签: c# asp.net gridview checkbox


    【解决方案1】:

    这里...

    (CType(gridview.Rows(0).Cells(5).Controls(0), CheckBox).Checked)
    

    【讨论】:

    • 添加一些解释,而不仅仅是一个 sn-p
    【解决方案2】:

    如果您为该控件指定了 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
    }
    

    【讨论】:

      【解决方案3】:

      自从我从事 GridView 工作以来已经有一段时间了。你试过了吗?

      protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)            
      {   
         var mycheckbox = (CheckBox)e.Row.Cells[5].Controls[0];
         var status = mycheckbox.checked;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-15
        • 2013-10-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多