Ask a Question related to ASP.NET General, Design and Development.
-
Ed Allan #1
Nested repeater databinding question
[url]http://ejaconsulting.com/nestedrepeater/NestedRepeater.txt[/url]
>-----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
>>adapted>>-----Original Message-----
>>I have created an ASP.Net page - see code below ->scid=kb;EN->>from [url]http://support.microsoft.com/default.aspx?[/url]>>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 -runs>>remove the grandchild repeater from the page and it>[Order>>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\"]")%>> </itemtemplate>>>><br>
>> </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>.>>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>
>>.
>>
>Ed Allan Guest
-
linkbutton in nested repeater doesnt fire
Hi! I've got a page with a datalist and a nested repeater in it to get "categories" and "sub categories". I've got link button in the datalist and... -
Nested Repeater question
Can someone help? I have a nested repeater in which I wish to format one of the bits of data in currency. I know that the code for the regular... -
Error with Nested Repeater
You probably won't have much luck here either since this is a "classic" asp group. But are you sure that "Reduction" is a property of your object... -
Nested Repeater - 3 levels - datasource
I have extended the example at http://support.microsoft.com/default.aspx?scid=kb;EN- US;306154 to build a webform page with 3 layers of nested... -
Nested Repeater Controls
I have extended the example at http://support.microsoft.com/default.aspx?scid=kb;EN- US;306154 to build a webform page with 3 layers of nested...



Reply With Quote

