문제

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