Home | 2.0 Content | Code Samples | Tips and Tricks | -- Tutorials -- | ASP.Net Books | Resources | Hosting
The Best Place Yet for ASP.Net - ASPNet101.com
Power Search


Don't Miss any New Content!
Sign up for Newsletter!

  Menu  
  Code Samples
Tips and Tricks
Tutorials
ASP.Net FAQ
Training
Resources
Hosting
Recommended Books
Home
 
     
  Our Sponsors :  
 
ASP Express WebHost4Life DotNetSlackers
 
     

69
If you find this site helpful, please donate to help keep it online


     
 
Nested DataLists (C# Version)
Categories & Products
Beverages
    Chai     Steeleye Stout     Laughing Lumberjack Lager
    Chang     Côte de Blaye     Outback Lager
    Guaraná Fantástica     Chartreuse verte     Rhönbräu Klosterbier
    Sasquatch Ale     Ipoh Coffee     Lakkalikööri
Condiments
    Aniseed Syrup     Northwoods Cranberry Sauce     Vegie-spread
    Chef Anton's Cajun Seasoning     Genen Shouyu     Louisiana Fiery Hot Pepper Sauce
    Chef Anton's Gumbo Mix     Gula Malacca     Louisiana Hot Spiced Okra
    Grandma's Boysenberry Spread     Sirop d'érable     Original Frankfurter grüne Soße
Confections
    Pavlova     Gumbär Gummibärchen     Maxilaku
    Teatime Chocolate Biscuits     Schoggi Schokolade     Valkoinen suklaa
    Sir Rodney's Marmalade     Zaanse koeken     Tarte au sucre
    Sir Rodney's Scones     Chocolade     Scottish Longbreads
    NuNuCa Nuß-Nougat-Creme
Dairy Products
    Queso Cabrales     Geitost     Gudbrandsdalsost
    Queso Manchego La Pastora     Raclette Courdavault     Flotemysost
    Gorgonzola Telino     Camembert Pierrot     Mozzarella di Giovanni
    Mascarpone Fabioli
Grains/Cereals
    Gustaf's Knäckebröd     Filo Mix     Ravioli Angelo
    Tunnbröd     Gnocchi di nonna Alice     Wimmers gute Semmelknödel
    Singaporean Hokkien Fried Mee
Meat/Poultry
    Mishi Kobe Niku     Thüringer Rostbratwurst     Tourtière
    Alice Mutton     Perth Pasties     Pâté chinois
Produce
    Uncle Bob's Organic Dried Pears     Rössle Sauerkraut     Longlife Tofu
    Tofu     Manjimup Dried Apples
Seafood
    Ikura     Inlagd Sill     Rogede sild
    Konbu     Gravad lax     Spegesild
    Carnarvon Tigers     Boston Crab Meat     Escargots de Bourgogne
    Nord-Ost Matjeshering     Jack's New England Clam Chowder     Röd Kaviar

(All Code Samples created with ASP Express)
Check out ASP Express for creating and editing your ASP/ASP.Net and HTML code!

Code Sample for
Nested DataLists (C# Version)

Sometimes, we need to nest data - say for instance - List the Categories, and under each Category, list the Products for that particular Category.

This sample uses the SQL Managed Provider to show exactly that, using the Categories and Products tables from the NorthWind Database.

As usual, just copy this code directly into a new page, change the database/connection information to match your system, and run it from your own computer.

You can read a Tutorial about this code here.

Thanks to Mike Houston for this code sample
http://www.nexus6studio.com

See this code in VB.Net

See the Code Below:


<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<HTML>
  <HEAD>
    <title>Nested Datalists Using C#</title>
  <script language=C# runat=server>
  void Page_Load(object sender, System.EventArgs e)
  {	
	string strConn = "Server=YourServer;uid=yourUID;pwd=YourPWD;database=Northwind";
	string MySQL = "Select CategoryID, CategoryName from Categories";
	SqlConnection MyConn = new SqlConnection(strConn);
	DataSet ds = new DataSet();

	SqlDataAdapter Cmd = new SqlDataAdapter(MySQL,MyConn);
	Cmd.Fill(ds,"Categories");

	SqlDataAdapter Cmd2 = 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"].DefaultView;
	DataBind();
  }
  </script>
  </HEAD>
  <body>
    <form id="Form1" method="post" runat="server">
<asp:DataList runat="server"
	Id="dlCategories"
	GridLines="Both"
	Bordercolor="black"
	cellpadding="3"
	cellspacing="0"
	Headerstyle-BackColor="#DDDDDD"
	Headerstyle-Forecolor="#777777"
	Headerstyle-Font-Name="Arial"
	Headerstyle-Font-Size="14"
	Headerstyle-Font-Bold="true"
	Font-Name="Arial"
	Font-Bold="true"
	Font-Italic="true"
	Font-Size="11"
	ForeColor="Red"
	RepeatColumns="1">
	<HeaderTemplate>
		Categories & Products
	</HeaderTemplate>
	<ItemTemplate><%# DataBinder.Eval(Container, "DataItem.CategoryName") %>
		 <br> 
 <asp:DataList runat="server" 
 Id="ChildDataList" 
 GridLines="None" 
 Bordercolor="black" 
 cellpadding="3" 
 cellspacing="0" 
 Headerstyle-BackColor="#8080C0" 
 Headerstyle-Font-Name="Arial" 
 Headerstyle-Font-Size="8" 
 Font-Name="Arial" 
 Font-Size="8" 
 datasource='<%# DataBinder.Eval(Container, "DataItem.myrelation") %>'
 RepeatColumns="3">
				<ItemTemplate>
					&nbsp; &nbsp; <%# DataBinder.Eval(Container, "DataItem.ProductName") %>
				</ItemTemplate>
			</ASP:DataList>
	</ItemTemplate>
</asp:DataList>
    </form>
	
  </body>
</HTML>
 
     
Home | 2.0 Content | Code Samples | Tips and Tricks | -- Tutorials -- | ASP.Net Books | Resources | Hosting
Send us your comments, questions or suggestions : Suggestions
Copyright © 2010 ASPNet101.com All Rights Reserved