我正在尝试在程序中动态绑定单选按钮列表。但我不知道如何插入值。
Aspx 页面代码
<asp:Table ID="tblSponser" runat="server" cellpadding="0" cellspacing="10" Visible="false"></asp:Table>
在下拉列表 selectedindex 事件上,我在后面的代码中绑定单选按钮
Protected Sub ddlVotes_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ddlVotes.SelectedIndexChanged
For SponserId = 0 To sponserDtst.Tables(0).Rows.Count - 1
Dim tr As New TableRow
Dim c1 As New TableCell
Dim c2 As New TableCell
Dim rbtyes As New RadioButtonList
rbtyes.ID = "rbtypes" & SponserId
rbtyes.ClientIDMode = UI.ClientIDMode.Static
rbtyes.Items.Add(New ListItem("Yes"))
rbtyes.Items.Add(New ListItem("No"))
rbtyes.RepeatDirection = RepeatDirection.Horizontal
c2.Controls.Add(rbtyes)
c2.Controls.Add(rbtyes)
tr.Controls.Add(c1)
tr.Controls.Add(c2)
tblSponser.Controls.Add(tr)
下面的代码不起作用。如何在按钮单击事件中获取单选按钮列表的值并存储在数据库中。
Protected Sub btnSubmitVote_Click(sender As Object, e As System.EventArgs) Handles btnSubmitVote.Click
Dim i As Integer
Dim x As Integer = 5
For i = 0 To x - 1
Dim str As String = "rbtypes" & i
Dim rb As RadioButtonList = CType(tblSponser.FindControl(str), RadioButtonList)
Dim ix As String = rb.SelectedValue
Next