Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Nested repeater databinding question

Reply
Thread Tools

Nested repeater databinding question

 
 
Ed Allan
Guest
Posts: n/a
 
      08-01-2003
http://ejaconsulting.com/nestedrepea...edRepeater.txt

>-----Original Message-----
>Doh! The HTML has all been rendered . . .
>
>Right click on this link and select 'Save target as ..'
>to get the code in a text file.
>
>Thanks - Ed
>
>>-----Original Message-----
>>I have created an ASP.Net page - see code below -

>adapted
>>from http://support.microsoft.com/default.aspx?

>scid=kb;EN-
>>US;306154 which contains 3 repeaters nested inside of
>>each other.
>>
>>When it executes it throws an InvalidCastException when
>>getting the datasource of the grandchild repeater.
>>However this datasource is fine for the child repeater -


>>remove the grandchild repeater from the page and it

runs
>>as expected.
>>
>>Can anyone tell me what is wrong with the datasource of
>>the grandchild repeater? What should it be?
>>
>>Thanks - Ed
>>
>>
>>HTML file:
>>==========
>><code>
>>
>><%@ Page language="c#"
>>Codebehind="NestedRepeater.aspx.cs"
>>AutoEventWireup="false"
>>Inherits="NestedRepeater.NestedRepeater" %>
>><%@ Import Namespace="System.Data" %>
>>
>><html>
>><head>
>><title>Nested Repeater Example</title>
>></head>
>><body>
>><form runat="server" id="Form1">
>>
>><!-- start parent repeater -->
>><asp:repeater id="parentRepeater" runat="server">
>> <itemtemplate>
>> <b>Company : <%# DataBinder.Eval
>>(Container.DataItem,"CompanyName") %></b><br/>
>>
>> <!-- start child repeater -->
>> <asp:repeater id="childRepeater" datasource='<%#
>>((DataRowView)Container.DataItem).Row.GetChildRo ws
>>("Customers_Orders") %>' runat="server">
>>
>> <itemtemplate>
>> - Order Date : <%# DataBinder.Eval
>>(Container.DataItem, "[\"OrderDate\"]")%><br/>
>>
>> <!-- start grandchild repeater -->
>> <asp:repeater id="grandChildRepeater"
>>datasource='<%# ((DataRowView)
>>Container.DataItem).Row.GetChildRows
>>("Orders_OrderDetails") %>' runat="server">
>> <itemtemplate>
>> - - Product ID : <%#
>>DataBinder.Eval(Container.DataItem, "[\"ProductID\"]")%
>>><br>

>> </itemtemplate>
>> </asp:repeater>
>> <!-- end grandchild repeater -->
>>
>> </itemtemplate>
>> </asp:repeater>
>> <!-- end child repeater -->
>>
>> </itemtemplate>
>></asp:repeater>
>><!-- end parent repeater -->
>>
>></form>
>></body>
>></html>
>>
>></code>
>>
>>Code behind file:
>>=================
>><code>
>>
>>using System;
>>using System.Data;
>>using System.Data.SqlClient;
>>using System.Web;
>>using System.Web.SessionState;
>>using System.Web.UI;
>>using System.Web.UI.WebControls;
>>
>>namespace NestedRepeater
>>{
>> public class NestedRepeater : System.Web.UI.Page
>> {
>> protected
>>System.Web.UI.WebControls.Repeater parentRepeater;
>>
>> public NestedRepeater()
>> {
>> Page.Init += new
>>System.EventHandler(Page_Init);
>> }
>>
>> public void Page_Load(object sender,
>>EventArgs e)
>> {
>> //Create the connection and
>>DataAdapter for the Customers (parent) table.
>> SqlConnection cnn = new
>>SqlConnection("Data Source=(local);Integrated
>>Security=SSPI;Trusted_Connection=yes;Initial
>>Catalog=Northwind;");
>> SqlDataAdapter daCustomers = new
>>SqlDataAdapter("select CustomerID, CompanyName from
>>Customers order by CompanyName", cnn);
>>
>> //Create a second DataAdapter for
>>the Orders (child) table.
>> SqlDataAdapter daOrders = new
>>SqlDataAdapter("select OrderID, CustomerID, OrderDate
>>from Orders order by OrderDate", cnn);
>>
>> //Create a third DataAdapter for
>>the OrderDetails (grandchild) table.
>> SqlDataAdapter daOrderDetails =
>>new SqlDataAdapter("select OrderID, ProductID from

>[Order
>>Details] order by OrderID", cnn);
>>
>> //Create and fill the DataSet.
>> DataSet ds = new DataSet();
>> DataTable dtCustomers =
>>ds.Tables.Add("Customers");
>> DataTable dtOrders = ds.Tables.Add
>>("Orders");
>> DataTable dtOrderDetails =
>>ds.Tables.Add("OrderDetails");
>> daCustomers.Fill(dtCustomers);
>> daOrders.Fill(dtOrders);
>> daOrderDetails.Fill
>>(dtOrderDetails);
>>
>> //Create the relation between the
>>Customers and Orders tables.
>> ds.Relations.Add
>>("Customers_Orders", ds.Tables["Customers"].Columns
>>["CustomerID"], ds.Tables["Orders"].Columns
>>["CustomerID"]);
>>
>> //Create the relation between the
>>Orders and OrderDetails tables.
>> ds.Relations.Add
>>("Orders_OrderDetails", ds.Tables["Orders"].Columns
>>["OrderID"], ds.Tables["OrderDetails"].Columns
>>["OrderID"]);
>>
>> //Bind the Authors table to the
>>parent Repeater control, and call DataBind.
>> parentRepeater.DataSource =
>>ds.Tables["Customers"];
>> Page.DataBind();
>>
>> //Close the connection.
>> cnn.Close();
>> }
>>
>> private void Page_Init(object sender,
>>EventArgs e)
>> {
>> InitializeComponent();
>> }
>>
>> private void InitializeComponent()
>> {
>> this.Load += new
>>System.EventHandler(this.Page_Load);
>> }
>> }
>>}
>>
>></code>
>>.
>>

>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Databinding expressions are only supported on objects that have a DataBinding event jobs ASP .Net 0 09-25-2007 11:54 PM
Gridview encoding, or how to run commands before gridview's default databinding, or, how do I disable default databinding at all? Sergei Shelukhin ASP .Net 1 11-12-2006 01:43 PM
Repeater control with nested repeater chris.reed@digus.com ASP .Net 0 02-11-2005 05:10 PM
XML DataBinding to the Repeater Control; =?Utf-8?B?THVkbWFs?= ASP .Net 0 04-05-2004 04:21 PM
DataGrid Custom Column Error when DataBinding "does not contain a definition for 'DataBinding'" Earl Teigrob ASP .Net Datagrid Control 1 03-01-2004 04:52 AM



Advertisments