Hi. I have just started transitioning from ASP to ASP.NET and I have run into a problem I need help with.
I have a listbox control on my .aspx page:
<ASP:LISTBOX ID="Sites" RUNAT="server" DATAVALUEFIELD="SiteID" DATATEXTFIELD="SiteName" ROWS="1">
This works fine. My listbox populates from my database.
I want to get the value of the selected item in my listbox. So in my aspx.vb file in the submit subroutine I have the line:
Dim SiteIDStr As String = Sites.SelectedItem.Value
When I submit my form I keep getting this error:
System.NullReferenceException: Object reference not set to an instance of an object.
I have tried many variations of the line giving me errors, but nothing I tried has worked. Can someone please shed some light on this?
Many many thanks in advance!
I have a listbox control on my .aspx page:
<ASP:LISTBOX ID="Sites" RUNAT="server" DATAVALUEFIELD="SiteID" DATATEXTFIELD="SiteName" ROWS="1">
This works fine. My listbox populates from my database.
I want to get the value of the selected item in my listbox. So in my aspx.vb file in the submit subroutine I have the line:
Dim SiteIDStr As String = Sites.SelectedItem.Value
When I submit my form I keep getting this error:
System.NullReferenceException: Object reference not set to an instance of an object.
I have tried many variations of the line giving me errors, but nothing I tried has worked. Can someone please shed some light on this?
Many many thanks in advance!