简体   繁体   中英

Checked property is not accessible in asp.net

I want to access "Checked" property against a checkbox control in GridView, please see my aspx page code below firstly:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
    <Columns>
    <asp:TemplateField>
        <HeaderTemplate>
        <asp:CheckBox ID="cbDeleteAll" runat="server" OnCheckedChanged="cbDeleteAll_CheckedChanged" />
        </HeaderTemplate>
        <ItemTemplate>
        <asp:CheckBox ID="cbDelete" runat="server" OnCheckedChanged="cbDelete_CheckedChanged" />
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Employee ID">
        <ItemTemplate>
        <asp:Label ID="lblEmpId" runat="server" Text='<%# Bind("DeptID") %>'></asp:Label>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="EmployeeName" HeaderText="Employee Name" />
    <asp:BoundField DataField="DeptID" HeaderText="Department" />
    </Columns>
</asp:GridView>    

in the "cbDeleteAll_CheckedChanged" event, I would like to see the Checked property on the header template and set value to Checked property to checkboxes in the item template, see below:

在此处输入图片说明

as you can see, there is a red wave line under "Checked" property, when I rebuild the solution, I can see the error message as below:

在此处输入图片说明

so, I was totally confused I don't know why I cannot access this property in the code? can anyone help me or give me some instructions?

Look at the error. It says WebApplication1.CheckBox . It appears you have a CheckBox class in your app and therefore you're casting to the wrong type. Don't name your classes the same thing as something built into the framework.

To find the offending file put your cursor over CheckBox in your class and press Function 12 or right click it and select Go To Definition. Then right click that class and rename it something more appropriate.

The correct CheckBox class is in System.Web.UI.WebControls namespace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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