Reputation: 1223
So I'm working in ASP.NET and VB.NET right now. Here's how I display my view:
<tr>
<td colspan="2">
<TABLE id="Table1" cellSpacing="0" cellPadding="0" width="100%" border="0">
<TR>
<TD>
<asp:repeater id="repVKM" runat="server">
<ItemTemplate>
<br>
<input id="radioBtnID" type="radio" name="radVKM" value='<%# DataBinder.Eval(container.Dataitem, "BJBVKMID") %>'>
<%# DataBinder.Eval(Container.DataItem, "BJBVKM") %>
</ItemTemplate>
</asp:repeater>
</TD>
</TR>
</TABLE>
</td>
</tr>
Here's how I fill the radiobuttons in the repeater:
Me.repVKM.DataSource = clsInschrijving2elijnManager.GetVoorkeurMateries(False)
Me.repVKM.DataBind()
And here's how I'm trying to see which radiobutton was checked:
Dim voorkeurMateries = repVKM.Items
Dim selectieVKM As String
For Each item As RepeaterItem In voorkeurMateries
Dim rb As RadioButton
rb = item.FindControl("radioBtnID")
If rb.Checked Then
selectieVKM = rb.Text
Exit For
End If
Next
It gives a "Nothing" error (like a null error) on the value for "rb" because it seems like he can't find the correct control? I don't know very much about VB.NET and ASP.NET so I can't seem to find the solution.
Upvotes: 0
Views: 29
Reputation: 35564
There are two problems with your code. First, there is no runat="server"
tag on the RadioButton so it can never be detected in code behind.
Second, you are looking for a RadioButton Control, while in the HTML you have a normal html radio.
So either add the runat=server to your existing RadioButton
<input id="radioBtnID" runat="server" type="radio" name="radVKM">
And change the code behind to
Dim radio As HtmlInputRadioButton = CType(item.FindControl("radioBtnID"),HtmlInputRadioButton)
Or make it a "real" aspnet control in the Repeater. Then the code in the loop is correct.
<asp:RadioButton ID="RadioButton1" runat="server" Text='<%# Eval("radVKM") %>' />
Upvotes: 1