Problem binding data to datalist

Discussion in 'ASP .Net' started by Laura K, Mar 25, 2005.

  1. Laura K

    Laura K Guest

    Can someone tell me where I went wrong. This is my code for binding data to
    a datalist.

    <script language="vb">
    Sub Page_Load(Src As Object, e As EventArgs)

    Dim Con As New SqlConnection("server=(PathToDataBase)"; &
    "database=name;User ID=UID;Password=password")
    Dim myCommand As New SqlDataAdapter
    myCommand= ("select distinct strSubCategory from tblProducts", con)

    Dim dgDataset = New DataSet()
    myCommand.Fill(dgDataset)

    datalist.DataSource = ds
    datalist.DataBind()

    end sub
    </script>

    <asp:DataList id="datalist" runat="server" HorizontalAlign="Center">
    <ItemTemplate>
    <%# DataBinder.Eval(Container.DataItem, "strSubCategory") %>
    </ItemTemplate>
    </asp:DataList>
     
    Laura K, Mar 25, 2005
    #1
    1. Advertising

  2. Laura K

    Karl Seguin Guest

    Do you get an error?

    You are missing runat="server" in the <script> tag....
    you aren't binding to dgDataSet...

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)


    "Laura K" <> wrote in message
    news:%...
    > Can someone tell me where I went wrong. This is my code for binding data

    to
    > a datalist.
    >
    > <script language="vb">
    > Sub Page_Load(Src As Object, e As EventArgs)
    >
    > Dim Con As New SqlConnection("server=(PathToDataBase)"; &
    > "database=name;User ID=UID;Password=password")
    > Dim myCommand As New SqlDataAdapter
    > myCommand= ("select distinct strSubCategory from tblProducts", con)
    >
    > Dim dgDataset = New DataSet()
    > myCommand.Fill(dgDataset)
    >
    > datalist.DataSource = ds
    > datalist.DataBind()
    >
    > end sub
    > </script>
    >
    > <asp:DataList id="datalist" runat="server" HorizontalAlign="Center">
    > <ItemTemplate>
    > <%# DataBinder.Eval(Container.DataItem, "strSubCategory") %>
    > </ItemTemplate>
    > </asp:DataList>
    >
    >
     
    Karl Seguin, Mar 26, 2005
    #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. Jordan
    Replies:
    2
    Views:
    2,559
    Jordan
    Feb 10, 2004
  2. Nevyn Twyll
    Replies:
    8
    Views:
    1,939
  3. buran
    Replies:
    0
    Views:
    469
    buran
    Apr 28, 2005
  4. Laura K

    Data not binding to datalist

    Laura K, Dec 28, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    680
    Laura K
    Dec 29, 2005
  5. JcFx
    Replies:
    0
    Views:
    302
Loading...

Share This Page