我试图在programm中动态绑定radiobutton列表。但是我愿意 不知道如何插入价值。
Aspx网页代码
<asp:Table ID="tblSponser" runat="server" cellpadding="0" cellspacing="10" Visible="false"></asp:Table>
on dropdownlist selectedindex事件我在Code中绑定单选按钮 后面
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)
下面的代码不起作用。如何获得radiobuttonlist和 按钮点击事件存储在数据库中。
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
答案 0 :(得分:0)
在页面加载过程中的哪个位置执行代码?您应该在OnInit方法中执行此操作才能正常工作。 看看这个 - 它提供了关于asp.net页面生命周期的好信息