Trouble binding a drop down list using a strongly typed stored proc

I'm starting a project using a Data Access Layer. I'm trying to bind a drop down list to a stored procedure that is implemented as follows:

haa_get_CategoriesTableAdapter <-- the defined table adapter
GetCateorgiesData() <-- the specified fill method using the stored proc

In the data design portion of VS2005, I can successfully return the dataset.

My problem is that I can not successfully bind to a drop down list. It's the syntax that I can't decipher. Here's the code that I currently have:

Imports CategoriesTableAdapters

Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub page_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim categoryAdapter As New haa_get_CategoriesTableAdapter
CategoryListBox.DataSource = categoryAdapter.GetCategoriesData
'CategoryListBox.DataTextField = categoryTable.
CategoryListBox.DataBind()
End Sub

End Class

When I 'show in browser' with the above code, I get a drop down box filled with 'System.Data.DataRowView', one for each record in the table.

I think I know that I need to be able to define CategoryListBox.DataTextField but I can't find the correct syntax.

Has anyone done this? Would you share the code with me?

Thanks,

Mary

Comments

  • I found the answer and thought it might help someone else if I posted it. The following code correctly displays the drop down list:

    Protected Sub page_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim categoryAdapter As New haa_get_CategoriesTableAdapter
    If Not Page.IsPostBack Then
    CategoryListBox.DataSource = categoryAdapter.GetCategoriesData
    CategoryListBox.DataTextField = "Code"
    CategoryListBox.DataBind()
    End If
    End Sub

    I was making it much more difficult than it needed to be.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion