Wrox Programmer Forums
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 10th, 2003, 01:29 PM
Authorized User
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataList in DataList

I have a problem something like this
I want to show in datalist customers but below to show orders for customer.

I created datalist control and inside it i have to label for CustomerID and CompanyName and bind these labels without problems to dataset. But I do not know what to do next. Can i put the other data list in the first or something else and how can i bind it.
Thanks a lot
Old December 2nd, 2003, 05:04 AM
Registered User
Join Date: Oct 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

Nested datalists are no problem. At least two deep...

Try this .aspx out (if you have SQL Server), modify as necessary:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
    <meta name="GENERATOR" Content="ASP Express 2.1">
    <title>Nested DataLists</title>
<script language="VB" runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
    Dim strConn as string = "server=localhost;uid=USERID;pwd=PASSWORD;database =Northwind"
    Dim MySQL as string = "Select CategoryID, CategoryName from Categories"
    Dim MyConn as New SQLConnection(strConn)
    Dim ds as DataSet=New DataSet()

    Dim Cmd as New SQLDataAdapter(MySQL,MyConn)

            Dim cmd2 As SqlDataAdapter = New SqlDataAdapter("select * from Products", MyConn)
            cmd2.Fill(ds, "Products")

            ds.Relations.Add("myrelation", ds.Tables("Categories").Columns("CategoryID"), ds.Tables("Products").Columns("CategoryID"))

    dlCategories.Datasource=ds.Tables("Categories").De faultView
End Sub

Function doFormat(sItem as Decimal)
    Dim s as String
    s=String.Format("{0:c}", sItem)
End function

<asp:DataList runat="server"
        Categories & Products
    <ItemTemplate><%# Container.DataItem("CategoryName")%>
            <asp:DataList runat="server"
                datasource='<%# Container.DataItem.Row.GetChildRows("myrelation") %>'
                    &nbsp; &nbsp; <%# Container.DataItem("ProductName") %>
                     - <%# doFormat(Container.DataItem("UnitPrice")) %>

Old July 9th, 2004, 04:31 PM
Registered User
Join Date: Jul 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts

Ok so what if one of the categories doesn't have anything under it. I get an error in that case. How do you suggest to get around it.

Daniel A. Miller
Old July 9th, 2004, 05:18 PM
Registered User
Join Date: Jul 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts

This constraint cannot be enabled as not all values have corresponding parent values.

Daniel A. Miller

Similar Threads
Thread Thread Starter Forum Replies Last Post
DataList pbyrum ASP.NET 2.0 Basics 2 December 3rd, 2009 04:01 PM
Datalist inside datalist amit.jagtap ASP.NET 2.0 Professional 1 September 4th, 2007 05:03 AM
Datalist cp75 ASP.NET 1.0 and 1.1 Professional 10 September 8th, 2006 11:38 AM
about datalist bvrao VS.NET 2002/2003 0 December 24th, 2003 06:15 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.