sj1187534
Well-known member
Hi.....This part of the code does not work for some reason...It is always giving me the same error that:
Object reference not set to an instance of an object
this is the whole code for the user control which loads the drop down list for states...
==========================================
Public MustInherit Class ddlState
Inherits System.Web.UI.UserControl
Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
Protected WithEvents SQLCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents ddlStates As System.Web.UI.WebControls.DropDownList
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim connect As SetUpDBConnect, dset As New DataSet
connect = New SetUpDBConnect("webGetState")
dset = connect.Get_State()
connect.Close()
Dim count As Integer, noOfRows As Integer
noOfRows = dset.Tables(0).Rows.Count
For count = 0 To noOfRows - 1
ddlStates.Items.Add(dset.Tables(0).Rows(count).Item(1))
Next count
End Sub
Function GetState() As String
Return ddlStates.SelectedItem.Value
End Function
Function SetListValue(ByVal curState As String)
ddlStates.Items.FindByText(curState).Selected = True
End Function
End Class
=======================================
It is giving me error on the 3 rd line from the bottom....I dont have a clue why it is doing so.....I really need some thought from someone else...I am out of ideas....Thanks..
SJ
Object reference not set to an instance of an object
this is the whole code for the user control which loads the drop down list for states...
==========================================
Public MustInherit Class ddlState
Inherits System.Web.UI.UserControl
Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
Protected WithEvents SQLCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents ddlStates As System.Web.UI.WebControls.DropDownList
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim connect As SetUpDBConnect, dset As New DataSet
connect = New SetUpDBConnect("webGetState")
dset = connect.Get_State()
connect.Close()
Dim count As Integer, noOfRows As Integer
noOfRows = dset.Tables(0).Rows.Count
For count = 0 To noOfRows - 1
ddlStates.Items.Add(dset.Tables(0).Rows(count).Item(1))
Next count
End Sub
Function GetState() As String
Return ddlStates.SelectedItem.Value
End Function
Function SetListValue(ByVal curState As String)
ddlStates.Items.FindByText(curState).Selected = True
End Function
End Class
=======================================
It is giving me error on the 3 rd line from the bottom....I dont have a clue why it is doing so.....I really need some thought from someone else...I am out of ideas....Thanks..
SJ