I have a dropdown
<div>
<asp:DropDownList ID="RegistrationDropDownList" runat="server">
<asp:ListItem Value="NULL">All records</asp:ListItem>
<asp:ListItem Value="1">Submitted records</asp:ListItem>
<asp:ListItem Value="0">Non-Submitted records</asp:ListItem>
</asp:DropDownList>
</div>
I want to Show/hide <asp:ListItem Value="NULL">All records</asp:ListItem> based on a session variable
So I tried like this
<asp:DropDownList ID="RegistrationDropDownList" runat="server">
<%if (Convert.ToInt32(Session["user_level"]) == 1){ %>
<asp:ListItem Value="NULL">All records</asp:ListItem>
<%}%>
<asp:ListItem Value="1">Submitted records</asp:ListItem>
<asp:ListItem Value="0">Non-Submitted records</asp:ListItem>
</asp:DropDownList>
But I got an error
code blocks are not supported in this context
I understand I cant use code blocks on controls that have the runat="server" but removing it breaks my code behind logic.
How can I solve this problem ?
Page_Loadyou can check the conditional and remove theNULLvalue item from theDropDownList. (Or the inverse, check the opposite condition to add theNULLvalue.)