469,625 Members | 893 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

Nested repeater databinding question

-----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 -

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

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 runsas expected.

Can anyone tell me what is wrong with the datasource of
the grandchild repeater? What should it be?

Thanks - Ed
HTML file:

<%@ Page language="c#"
Inherits="NestedRepeater.NestedRepeater" %>
<%@ Import Namespace="System.Data" %>

<title>Nested Repeater Example</title>
<form runat="server" id="Form1">

<!-- start parent repeater -->
<asp:repeater id="parentRepeater" runat="server">
<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">

- Order Date : <%# DataBinder.Eval
(Container.DataItem, "[\"OrderDate\"]")%><br/>

<!-- start grandchild repeater -->
<asp:repeater id="grandChildRepeater"
datasource='<%# ((DataRowView)
("Orders_OrderDetails") %>' runat="server">
- - Product ID : <%#
DataBinder.Eval(Container.DataItem, "[\"ProductID\"]")%

<!-- end grandchild repeater -->

<!-- end child repeater -->

<!-- end parent repeater -->



Code behind file:

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
System.Web.UI.WebControls.Repeater parentRepeater;

public NestedRepeater()
Page.Init += new

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
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

Details] order by OrderID", cnn);

//Create and fill the DataSet.
DataSet ds = new DataSet();
DataTable dtCustomers =
DataTable dtOrders = ds.Tables.Add
DataTable dtOrderDetails =

//Create the relation between the
Customers and Orders tables.
("Customers_Orders", ds.Tables["Customers"].Columns
["CustomerID"], ds.Tables["Orders"].Columns

//Create the relation between the
Orders and OrderDetails tables.
("Orders_OrderDetails", ds.Tables["Orders"].Columns
["OrderID"], ds.Tables["OrderDetails"].Columns

//Bind the Authors table to the
parent Repeater control, and call DataBind.
parentRepeater.DataSource =

//Close the connection.

private void Page_Init(object sender,
EventArgs e)

private void InitializeComponent()
this.Load += new



Nov 17 '05 #1
0 5213

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by hendrik.vanniekerk | last post: by
3 posts views Thread by Eirik Eldorsen | last post: by
2 posts views Thread by Allan Ebdrup | last post: by
2 posts views Thread by Josh | last post: by
1 post views Thread by andrew.douglas11 | last post: by
12 posts views Thread by =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.