简体   繁体   English

表格复选框。未选中

[英]Forms checkbox.Checked not recognised

I'm having troubles with recognizing .Checked . 我在识别.Checked遇到了麻烦。 I'm getting this error 我收到这个错误

'HtmlGenericControl' does not contain a definition for 'Checked' and no extension method 'Checked' 'HtmlGenericControl'不包含'Checked'的定义,也没有扩展方法'Checked'

Which namespace am I missing/not have to use the .Checked property? 我缺少/不必使用.Checked属性是哪个名称空间?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace 
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Radio1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Radio1.SelectedIndex == 0)
            {
                Checkbox1.Visible = true;
            }
            else
            {
                Checkbox1.Visible = false;
                Checkbox1.Checked = false;
            }
        }
    }
}

使用ASP复选框而不是HTML输入类型checkbox

<asp:CheckBox ID="CheckBox1" runat="server" oncheckedchanged="CheckBox1_CheckedChanged" AutoPostBack="true" />

I guess you didn't set the property Autopostback = "true" for radiobutton list. 我猜您没有为单选按钮列表设置属性Autopostback =“ true”。

 <asp:RadioButtonList ID="RadioButtonList1" runat="server" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" AutoPostBack="True">
            <asp:ListItem Value="1" Text="1">                </asp:ListItem>
            <asp:ListItem Value="2" Text="2">            </asp:ListItem>
        </asp:RadioButtonList>
        <asp:CheckBox ID="CheckBox1" runat="server" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM