0

当我将列表项动态分配给单选按钮列表时,各个列表项的值属性等于该列表项的文本值。简而言之,我的值不用于属性值。

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>    
4

1 回答 1

2

您不能像这样分配项目集合。正确的方法是:

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


     foreach (ListItem item in items)
          rblCompanyType.Items.Add(item);
于 2013-09-18T21:01:20.823 回答