473,756 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Nested repeater databinding question

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 InvalidCastExce ption 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:
==========
<code>

<%@ Page language="c#"
Codebehind="N estedRepeater.a spx.cs"
AutoEventWire up="false"
Inherits="Nes tedRepeater.Nes tedRepeater" %>
<%@ Import Namespace="Syst em.Data" %>

<html>
<head>
<title>Nest ed Repeater Example</title>
</head>
<body>
<form runat="server" id="Form1">

<!-- start parent repeater -->
<asp:repeat er id="parentRepea ter" runat="server">
<itemtemplate >
<b>Company : <%# DataBinder.Eval
(Container.Da taItem,"Company Name") %></b><br/>

<!-- start child repeater -->
<asp:repeater id="childRepeat er" datasource='<%#
((DataRowView )Container.Data Item).Row.GetCh ildRows
("Customers_O rders") %>' runat="server">

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

<!-- start grandchild repeater -->
<asp:repeater id="grandChildR epeater"
datasource='< %# ((DataRowView)
Container.Dat aItem).Row.GetC hildRows
("Orders_Orde rDetails") %>' runat="server">
<itemtemplate >
- - Product ID : <%#
DataBinder.Ev al(Container.Da taItem, "[\"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.Sql Client;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;

namespace NestedRepeater
{
public class NestedRepeater : System.Web.UI.P age
{
protected
System.Web.UI .WebControls.Re peater parentRepeater;

public NestedRepeater( )
{
Page.Init += new
System.EventH andler(Page_Ini t);
}

public void Page_Load(objec t sender,
EventArgs e)
{
//Create the connection and
DataAdapter for the Customers (parent) table.
SqlConnection cnn = new
SqlConnection ("Data Source=(local); Integrated
Security=SSPI ;Trusted_Connec tion=yes;Initia l
Catalog=North wind;");
SqlDataAdapter daCustomers = new
SqlDataAdapte r("select CustomerID, CompanyName from
Customers order by CompanyName", cnn);

//Create a second DataAdapter for
the Orders (child) table.
SqlDataAdapter daOrders = new
SqlDataAdapte r("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.Fil l(dtCustomers);
daOrders.Fill(d tOrders);
daOrderDetails. Fill
(dtOrderDetai ls);

//Create the relation between the
Customers and Orders tables.
ds.Relations.Ad d
("Customers_O rders", ds.Tables["Customers"].Columns
["CustomerID "], ds.Tables["Orders"].Columns
["CustomerID "]);

//Create the relation between the
Orders and OrderDetails tables.
ds.Relations.Ad d
("Orders_Orde rDetails", ds.Tables["Orders"].Columns
["OrderID"], ds.Tables["OrderDetai ls"].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(objec t sender,
EventArgs e)
{
InitializeCompo nent();
}

private void InitializeCompo nent()
{
this.Load += new
System.EventH andler(this.Pag e_Load);
}
}
}

</code>
.

.

Nov 17 '05 #1
0 5401

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3296
by: hendrik.vanniekerk | last post by:
Hi I'm using a repeater control doing databinding to an array at runtime. I have created a Template class for creating Headertemplate Itemtemplate etc. creating databinding at runtime. It contains an eventhandler that is added to the Databinding event of the repeater control In the Microsoft help it is said that the ItemCommand event of the repeater control will not capture an embedded
3
14728
by: DonRex | last post by:
Hello all! I couldn't find a web application-newsgroup for ASP.NET, so I'm sorry if this is the wrong forum! Synopsis: In my webform I have 3 nested repeaters: rpWeeks ----- rpTime
3
4040
by: Eirik Eldorsen | last post by:
Im trying to make a nested repeater with 3 levels. I've successfully created a nested repeater with 2 levels, but when adding the 3rd level I get an InvalidCastException. What am I doing wrong? Here is my code: <asp:Repeater id="level1Repeater" runat="server"> <itemtemplate>
0
1261
by: KJ | last post by:
I noticed the following behavior: With 2 repeaters nested, such as: <asp:repeater id=rptrParentRepeater runat="server"> <ItemTemplate> <asp:Repeater id="rptrChildRepeater" runat="server" DataSource="<%# ((DataRowView)Container.DataItem).Row.GetChildRows(RELATION_NAME)%>"> <ItemTemplate>
2
4283
by: Allan Ebdrup | last post by:
Hi, I'm trying to render a Matrix question in my ASP.Net 2.0 page, A matrix question is a question where you have several options that can all be rated according to several possible ratings (from less to more for example). I have a question object that has two properties that contain the collections Options and Ratings. now I want this kind of layout: --- Rating1 Rating2 Rating3 Option 1 () () ...
7
3008
by: | last post by:
I have what's probably a simple page lifecycle question related to dynamically evaluating values that are placed by a repeater and dynmically placing user controls that use those values. I'm attempting to bind a user control I've written, "ImageBox", to a repeater. The user control takes a custom property, "ContentID", that will execute a database lookup and load an image.
2
4950
by: Josh | last post by:
I have a nested repeater situation with a Link Button on the nested repeater. However when the link button is clicked I get a postback but the event never takes place. I'm trying to wire up the nested repeaters ItemCommand event in the ItemDataBound of the outer repeater. I have even tried sharing the Outer repeaters ItemCommand event but it still does not fire. I'm missing a trick here, can you tell me what it is?
1
1872
by: andrew.douglas11 | last post by:
Hello all, Is it possible to share controls inside a child repeater? Here's the situation: I have a web page that needs to display data grouped by A, and alternatively by B (only one grouping displayed at a time through Panel.Visible). A and B both share common child data: C. I have 2 parent repeaters corresponding to A and B, and each of those repeaters have 1 child repeater containing child data C. Presently, my code handles...
12
2178
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I'm doing a web app in VB/Dot Net 2.0. I'm probably a bit rusty and I have no experience using the repeater control. I have a user control I've created with multiple properties. I've created a test page and I've managed to bind the usercontrol to a repeater and display some data in the following fashion: <asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource1"> <ItemTemplate > <uc1:AUserControl runat="server"...
0
9255
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9819
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9689
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7226
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6514
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5119
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5289
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2647
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.