Retrieving value from combo box?
Retrieving value from combo box?
Retrieving value from combo box?
Retrieving value from combo box?
Retrieving value from combo box?
Retrieving value from combo box? Retrieving value from combo box? Retrieving value from combo box? Retrieving value from combo box? Retrieving value from combo box? Retrieving value from combo box? Retrieving value from combo box? Retrieving value from combo box?
Retrieving value from combo box? Retrieving value from combo box?
Retrieving value from combo box?
Go Back  Xtreme Visual Basic Talk > > > Retrieving value from combo box?


Reply
 
Thread Tools Display Modes
  #1  
Old 05-21-2010, 05:18 PM
kawi6rr kawi6rr is offline
Newcomer
 
Join Date: Jan 2009
Posts: 9
Default Retrieving value from combo box?


I have a databound combo box in the sub page_load that I'm trying to get the value from but keep getting this error.

Object reference not set to an instance of an object.

I have a button click event that I need to retrieve this value so that when its clicked a datagrid will be created based on the selected value. Any help is greatly appreciated.

Connection Code and data binding!
Public Sub Page_Load(sender as Object, e as EventArgs)
'1. Create a connection
Dim myConnection as SQLconnection
'Dim myConnection as New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
myConnection = New SQLconnection("server=xxxx; database=xxxx; uid=xxxx; pwd=xxxx")
'2. Create the command object, passing in the SQL string
Const strSQL as String = "SELECT DISTINCT Prov FROM OPPE_Clinic"
Dim myCommand as New SqlCommand(strSQL, myConnection)
'3. Create the DataReader
myConnection.Open()

Dim objDR as SqlDataReader
objDR = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

'Databind the DataReader to the listbox Web control
practName.DataSource = objDR
practName.DataBind()

'Add a new listitem to the beginning of the listitemcollection
practName.Items.Insert(0, new ListItem("-- Select Provider --"))
End Sub

Button Click event I'm trying to retrieve the combo box value with.

Public Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim submit As Button
Dim pracText As TextBox
pracText.text = practName.SelectedItem.text

End Sub
<form name="form1" runat="server">
<table border=0 bgcolor="#F9F9F2" height=455 width=900>
<tr>
<td><asp:listbox id="practName" runat="server" Rows="1" DataTextField="Prov" AutoPostBack="True" />&nbsp;&nbsp;<asp:textbox id="pracText" runat="server" Width="100" />&nbsp;&nbsp;<asp:Button id="submit" runat="server" Text="Submit" OnClick="Submit_Click" />
</td>
</tr>
</table>
</form>
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Retrieving value from combo box?
Retrieving value from combo box?
Retrieving value from combo box? Retrieving value from combo box?
Retrieving value from combo box?
Retrieving value from combo box?
Retrieving value from combo box? Retrieving value from combo box? Retrieving value from combo box? Retrieving value from combo box? Retrieving value from combo box? Retrieving value from combo box? Retrieving value from combo box?
Retrieving value from combo box?
Retrieving value from combo box?
 
Retrieving value from combo box?
Retrieving value from combo box?
 
-->