I have this code
<asp:RadioButtonList ID="rblSplitWeek" runat="server">
<asp:ListItem selected="true">No Choice</asp:ListItem>
<asp:ListItem Text = "First" Value = "Session('s_price_1')"></asp:ListItem>
<asp:ListItem Text = "Second"></asp:ListItem>
</asp:RadioButtonList>
But keep getting an error when trying to put the session variable in
Many thanks
Jamie
Unfortunately, data binding syntax (
<%# %>) is not supported in this context, and literal binding syntax (<%= %>or<%: %>) do not produce the desired results when assigning values to server controls.Here are a few alternate approaches:
1. Bind to a data source:
If you created a collection of objects containing text and value, you could easily set the DataSource, DataTextField, and DataValueField properties of the radio button list. Because the data source would be populated in code-behind, access to session variables is trivial.
For example, in markup:
And in code-behind:
2. Assign the value from code-behind
If you declare the list item with text but without value, you can set the value from script.
For example, in markup:
And in code-behind: