View Single Post
  #2 (permalink)  
Old December 21st, 2004, 05:58 AM
nashnash nashnash is offline
Authorized User
Join Date: Sep 2004
Location: , , .
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to nashnash

Please copy and pase this code and this will give you the result as you need
-----------------------------save this as 'nested.aspx'--------

<%@ Import Namespace="System.Data" %>
<%@ Page language="c#" Codebehind="nested.aspx.cs" AutoEventWireup="false" Inherits="Insight.nested" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="">
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
            <asp:repeater id="parentRepeater" runat="server">

                    <table border="1" width="300" >
                            <td width="100"><b>Size</b></td>
                            <td width="100"><b>Stock</b></td>
                            <td width="100"><b>Price</b></td>
                    <table border=1 width="300">
                            <td width="100"><b><%# DataBinder.Eval(Container.DataItem,"Brand") %></b></td>
                            <td width="200" align=center ><b><%# DataBinder.Eval(Container.DataItem,"Code") %></b></td>
                                <asp:repeater id="childRepeater" datasource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows ("myrelation") %>' runat="server">
                                    <table border=1 width="300">
                                        <td width="100"><%# DataBinder.Eval(Container.DataItem, "[size]")%></td>

                                        <td width="100"><%#CheckStock(Convert.ToInt32(DataBind er.Eval(Container.DataItem, "[stock]")))%></td>

                                        <td width="100"><%# DataBinder.Eval(Container.DataItem, "[price]")%></td>


------------Save this as 'nested.aspx.cs'----------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace Insight
    /// <summary>
    /// NASIM aHMAD
    /// 21/12/2004
    /// </summary>
    public class nested : System.Web.UI.Page
        protected System.Web.UI.WebControls.Repeater parentRepeater;

        private void Page_Load(object sender, System.EventArgs e)
            SqlConnection cnn = new SqlConnection("server=INSIGHT;UID=sa;PWD=Insight;d atabase=Pubs;"); //cHANGE YOUR CONNECTION STRING HERE
            SqlDataAdapter cmd1 = new SqlDataAdapter("select * from product",cnn);

            //Create and fill the DataSet.
            DataSet ds = new DataSet();

            //Create a second DataAdapter for the Stock table.
            SqlDataAdapter cmd2 = new SqlDataAdapter("select * from stock",cnn);

            //Create the relation bewtween the product and stock tables.

            //Bind the product table to the parent Repeater control, and call DataBind.
            parentRepeater.DataSource = ds.Tables["product"];

            //Close the connection.

        // This function will take the stock and
        // retrun you the label if there is Stock
        // it will print Stock other wise it will
        // print 'No Stock'
        protected string CheckStock(int Stock)
                return Stock.ToString();

                return "No Stock";

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
            this.Load += new System.EventHandler(this.Page_Load);


Please change your connection string here
SqlConnection cnn = new SqlConnection("server=INSIGHT;UID=sa;PWD=Insight;d atabase=Pubs;"); //cHANGE YOUR CONNECTION STRING HERE

in "nested.aspx.cs"

i have kept the table name as 'product' and 'stock' and same column name as you sepcified...

Please let me know if it doesnt work for you.