Reputation: 1239
I have a gridview that has a register checkbox and a waitlist checkbox depending on some values I hide one of the checkboxes and display a star for some odd reason when I run my website one time it evaluates to true the next time i get some error saying
Checked The name 'Checked' does not exist in the current context
.aspx
<asp:TemplateField HeaderText="Register" ItemStyle-CssClass="template-center">
<ItemTemplate >
<asp:CheckBox ID="chkRegister" runat="server"/>
<asp:Label ID="lblStarRegister" runat="server" Text="*" ForeColor="Red"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Wait List" ItemStyle-CssClass="template-center">
<ItemTemplate>
<asp:CheckBox ID="chkWaitList" runat="server" />
<asp:Label ID="lblStarWaitList" runat="server" Text="*" ForeColor="Red"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
code behind
if ((((CheckBox)row.FindControl("chkRegister")).Checked == true) || (((CheckBox)row.FindControl("chkWaitList")).Checked == true))
Upvotes: 0
Views: 157
Reputation: 14440
Visible = false
will not render your control. Use display:none
to hide your control. It will be available.
Edit:
Use css like
.hiddenelement
{
display:none;
}
Apply this class on the checkbox you want to hide. like
<asp:CheckBox ID="chkRegister" runat="server" CssClass="hiddenelement"/>
The checkbox will be hidden but available in code behind.
Edit2:
if (true)
{
chkRegister.CssClass = "displaynone";
}
else
{
chkRegister.CssClass = chkRegister.CssClass.Replace("displaynone", "");
}
Upvotes: 1