Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    47
    Thanks
    2
    Thanked 1 Time in 1 Post

    Function not returning DropDown Datasource

    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)
    myConn.Open()
    '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:

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

    Why is the dropdownlist empty when it is displayed?

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Nov 2006
    Posts
    47
    Thanks
    2
    Thanked 1 Time in 1 Post
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •