Re: Function Returns Empty DataSet

Discussion in 'ASP .Net' started by Goofy, Dec 12, 2006.

  1. Goofy

    Goofy Guest

    You need to DataBind your dropdown box.

    ddCats.DataBind



    "Erica" <> wrote in message
    news:...
    >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?
    Goofy, Dec 12, 2006
    #1
    1. Advertising

  2. Goofy

    Goofy Guest

    You can put the databind statement directly after you set the DataSource if
    you want, alternatively you can put a catchall DataBind to bind the whole
    page in the pre-render event.


    "Erica" <> wrote in message
    news:...
    > Thanks Goofy. That's exactly where I was missing it. One other question.
    > Where's the best place to put the databind. I have a couple of different
    > dropdowns that are auto populated and a datagrid. Should I put it in the
    > Page
    > Load event?
    >
    > "Goofy" wrote:
    >
    >>
    >> You need to DataBind your dropdown box.
    >>
    >> ddCats.DataBind
    >>
    >>
    >>
    >> "Erica" <> wrote in message
    >> news:...
    >> >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?

    >>
    >>
    >>
    Goofy, Dec 12, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vizlab
    Replies:
    3
    Views:
    4,196
    Michael Bar-Sinai
    Oct 17, 2007
  2. ++imanshu
    Replies:
    7
    Views:
    467
    ++imanshu
    Aug 23, 2008
  3. Joe
    Replies:
    3
    Views:
    757
    Joe Kaplan
    Feb 19, 2009
  4. Timo
    Replies:
    2
    Views:
    442
  5. Trans
    Replies:
    2
    Views:
    222
    Trans
    Nov 6, 2005
Loading...

Share This Page