ivgoneriding
Member
- Joined
- Feb 4, 2011
- Messages
- 10
- Programming Experience
- Beginner
Please forgive me, I am a complete newb.
I have the following code which runs as part of my onpage load in a ASP.NET project and populates a drop down list from a SQL DB:
Dim sConnectionString = ConfigurationManager.ConnectionStrings("Freshhoovesdb").ConnectionString
Dim cxConn As SqlConnection
Dim cxCommand As SqlCommand
Dim cxSqlDataReader As SqlDataReader
Dim sSQL As String
Dim sConn As String
sSQL = "SELECT * FROM PersonType"
sConn = sConnectionString
cxConn = New SqlConnection(sConn)
cxConn.Open()
cxCommand = New SqlCommand(sSQL, cxConn)
cxSqlDataReader = cxCommand.ExecuteReader()
ddlSelectPersonType.DataSource = cxSqlDataReader
ddlSelectPersonType.DataBind()
ddlSelectPersonType.Items.Insert(0, New ListItem("(Select)"))
cxConn.Close()
I would like to be able to reuse this code on other pages within my project, so would like to be able to move it to my class page, but am having trouble because the ddlselectpersontype is not declared in the base code - how do I declare a dropdownlist from a page in the base code?
Thanks
I have the following code which runs as part of my onpage load in a ASP.NET project and populates a drop down list from a SQL DB:
Dim sConnectionString = ConfigurationManager.ConnectionStrings("Freshhoovesdb").ConnectionString
Dim cxConn As SqlConnection
Dim cxCommand As SqlCommand
Dim cxSqlDataReader As SqlDataReader
Dim sSQL As String
Dim sConn As String
sSQL = "SELECT * FROM PersonType"
sConn = sConnectionString
cxConn = New SqlConnection(sConn)
cxConn.Open()
cxCommand = New SqlCommand(sSQL, cxConn)
cxSqlDataReader = cxCommand.ExecuteReader()
ddlSelectPersonType.DataSource = cxSqlDataReader
ddlSelectPersonType.DataBind()
ddlSelectPersonType.Items.Insert(0, New ListItem("(Select)"))
cxConn.Close()
I would like to be able to reuse this code on other pages within my project, so would like to be able to move it to my class page, but am having trouble because the ddlselectpersontype is not declared in the base code - how do I declare a dropdownlist from a page in the base code?
Thanks