Hopefully this is something simple, but I'm failry new to VB and ASP.NET and I'm trying to figure something out. Lets say I have two radiobuttonlists. One is populated in in asp.net while the other is populated via a hashtable in the vb.net code behind.
I then have a button that displays the selected items from the two radiolists when its clicked. Seems simple, but for the life of me I cannot get the radiobuttonlist that is populated from the hashtable to work properly. When I click the button I get the "Object reference not set to an instance of an object" error like the object isn't even there.
Anyway, here's the code. I'm very new to VB so I'm sure this is something simple.
ASP.NET
VB.NET
If I comment out the Label3.Text line at the end everything with the first radiobuttonlist works just fine and the selected value is returned. Its only when I uncomment the Label3.Text line at the end and reference RadioButtonList2.SelectedItem.Value that I get problem.
Thanks for any help/tips.
I then have a button that displays the selected items from the two radiolists when its clicked. Seems simple, but for the life of me I cannot get the radiobuttonlist that is populated from the hashtable to work properly. When I click the button I get the "Object reference not set to an instance of an object" error like the object isn't even there.
Anyway, here's the code. I'm very new to VB so I'm sure this is something simple.
ASP.NET
VB.NET:
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Value="0001">test1</asp:ListItem>
<asp:ListItem Value="0002">test2</asp:ListItem>
</asp:RadioButtonList>
<asp:RadioButtonList ID="RadioButtonList2" runat="server">
</asp:RadioButtonList>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
VB.NET:
Public Class Test
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = "Radio Table Test"
Dim ht1 As Hashtable = New Hashtable
ht1.Add("Radio Item 1", "001")
ht1.Add("Radio Item 2", "002")
ht1.Add("Radio Item 3", "003")
ht1.Add("Radio Item 4", "004")
RadioButtonList2.DataSource = ht1
RadioButtonList2.DataTextField = "key"
RadioButtonList2.DataValueField = "value"
RadioButtonList2.DataBind()
Button1.Text = "Submit"
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label2.Text = "Radio Button Value = " & RadioButtonList1.SelectedItem.Value
Label3.Text = "Radio Button List 2 Value = " & RadioButtonList2.SelectedItem.Value
End Sub
End Class
If I comment out the Label3.Text line at the end everything with the first radiobuttonlist works just fine and the selected value is returned. Its only when I uncomment the Label3.Text line at the end and reference RadioButtonList2.SelectedItem.Value that I get problem.
Thanks for any help/tips.