tags:

views:

18

answers:

1

Hi,

I must be doing something wrong here but I can't find an easy way to get this to work.

Imagine the following code:

<asp:RadioButtonList ID="MyRadioButtonList" runat="server">
    <asp:ListItem Value="<%= CompanyName.SystemName.Constants.PaymentFrequency.FREQUENT.ToString() %>" Text="Yes" Selected="True"></asp:ListItem>
    <asp:ListItem Value="<%= CompanyName.SystemName.Constants.PaymentFrequency.ONCE.ToString() %>" Text="No, Just do this once"></asp:ListItem>
</asp:RadioButtonList>

But it doesn't compile the statement before it renders the page. So if I get the selected value of this radiobuttonlist it contains something like "<%= Compan... %>" instead of what my constant defines.

What is the correct syntax for this?

A: 

I don't know why exactly (I didn't manage to find a reference) but the <%= %> syntax doesn't work when you are setting the Value or the Text of a ListItem, in ASPX mark-up.

You could instead do it from code-behind, like:

MyRadioButtonList.Items.Add(new ListItem(
    "Yes", CompanyName.SystemName.Constants.PaymentFrequency.FREQUENT.ToString()));
//...
Dan Dumitru
They accidentally forgot to put this in or something? This sucks :-)
Peter