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>    
有帮助吗?

解决方案

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top