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
Loading
SeanPosted May 24, 2010, 1:44 PM
Name 'practTest' is not declared.
What I'm trying to do with this code is fill a datagrid based on the selected item from the select list. For some reason I can't get the value to fill a text box let alone a datagrid. My datagrid will ultimately be filled with the following sql string, two textboxes and a select list.
strTxt = "SELECT MRN, CheckInDate, Dept, DX1, DX1Desc, CPT1, CPT1Desc FROM OPPE_Clinic WHERE CheckInDate >= '"& strDateOne & "' and CheckInDate <= '" & strDateTwo & "' and selectList = '"& selectedPract &"' ORDER BY CheckInDate ASC"
Syed ShakeerPosted May 23, 2010, 2:40 AM
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
In the above code you had created a textbox in .asp source page.Them why your again creating a textbox as
'Dim pracText As TextBox '
No need to to create an again the object of textbox.
let try with the below code:-
Public Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
pracText.text = practName.SelectedItem.text
End Sub