N
Nosaj
Houston, we've got a problem...
In a ascx file, I bind a datasource with a dropdownlist. The following
code runs perfectly in a aspx file but not in a ascx file. And I just
can't understand it. I changed many time my Page_Load function, but
nothing happened...
Function MyQueryMethod() As System.Data.DataSet
Dim connectionString As String = "server='XXX'; user
id='XXX'; password='XXX'; database='XXX'"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT [XXX].[LIBELLE] FROM
[XXX]"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New
System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function
Sub Page_Load(Sender As Object, E As EventArgs)
If Not Page.IsPostBack Then
DropDownList2.DataTextField = "LIBELLE"
DropDownList2.DataSource = MyQueryMethod()
DropDownList2.DataBind()
End If
End Sub
In a ascx file, I bind a datasource with a dropdownlist. The following
code runs perfectly in a aspx file but not in a ascx file. And I just
can't understand it. I changed many time my Page_Load function, but
nothing happened...
Function MyQueryMethod() As System.Data.DataSet
Dim connectionString As String = "server='XXX'; user
id='XXX'; password='XXX'; database='XXX'"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT [XXX].[LIBELLE] FROM
[XXX]"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New
System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function
Sub Page_Load(Sender As Object, E As EventArgs)
If Not Page.IsPostBack Then
DropDownList2.DataTextField = "LIBELLE"
DropDownList2.DataSource = MyQueryMethod()
DropDownList2.DataBind()
End If
End Sub