View Full Version : Function not returning DropDown Datasource

12-11-2006, 10:35 PM
I have a drop down list named ddCats. It's datasource is a public function called GetCatagories(). Here is the code for the function:

Public Function GetCategories() As DataSet
Dim myAuthenticate As New myAuth
Dim myConn As New MySql.Data.MySqlClient.MySqlConnection(myAuthenticate.DecryptConnectionString)
'Populate the ddlDataSet
Const strSQLDDL As String = "select lookup_value,lookup_id,ShortName from lookup where lookup_id = 'categoryID'"
Dim myDataAdapter As New MySql.Data.MySqlClient.MySqlDataAdapter(strSQLDDL, myConn)
myDataAdapter.Fill(ddlDataSet, "Categories")
Return ddlDataSet
End Function

ddlDataSet is declared as a global variable.

Why is the drop down list showing up empty. The select statement when ran directly against the mySql table returns 4 records. Here is the relevant HTML:

<asp:DropDownList id=ddCats runat="server" Visible="False" Width="158px" DataTextField="ShortName" DataValueField="lookup_value" DataSource="<%# GetCategories() %>"></asp:DropDownList>

Why is the dropdownlist empty when it is displayed?

12-12-2006, 03:17 PM
Why return a global variable? That's rather odd.

That said, this looks more like .net than classic asp. Are you calling databind() on page_load? Because that isn't called for you.

The general order of events is to run the query, adapter.fill(dataset), then element.databind(). I don't see a databind call here.

12-12-2006, 04:12 PM
I made it a global variable because I have three functions that grab database info on the page. Rather than opening and closing seperate objects for each of the functions I work with just one global one. I know it seems strange but it gives the code a cleaner look and it doesn't affect the performance at all.

I am using .net, but the forum description said ASP or ASP.NET and since that one had more people replying I though I would give it a try in that one.

Thanks for your help, I think I may have found my problem. I set the datasouce of the control to the function which in turn returns a dataset. The dataset it returns is set as the controls datasource inside the actual page.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum