Question

When I assign listitems dynamically to a radiobuttonlist, the value attribute of the individual listitems is equal to the text value of that listitem. In short, my value is not used for the attribute value.

Dim items As New ListItemCollection()
items.Add(New ListItem("hi there", "30"))

rblCompanyType.DataSource = items
rblCompanyType.DataBind()

<asp:RadioButtonList ID="rblCompanyType" Width="490" RepeatColumns="2" RepeatDirection="Vertical" runat="server"></asp:RadioButtonList>



<table style="width:490px;" id="CPHCenter_rblCompanyType">
    <tbody><tr>
        <td>
            <input type="radio" value="hi there" name="ctl00$CPHCenter$rblCompanyType" id="CPHCenter_rblCompanyType_0">
            <label for="CPHCenter_rblCompanyType_0">hi there</label>
        </td>
    </tr>
    </tbody>
</table>    
Was it helpful?

Solution

You can't assign the items collection like this. The correct way is:

  Dim items As New ListItemCollection()
     items.Add(New ListItem("hi there", "30"))


     foreach (ListItem item in items)
          rblCompanyType.Items.Add(item);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top