Nested Repeater
Nested Repeater
Nested Repeater
Nested Repeater
Nested Repeater
Nested Repeater Nested Repeater Nested Repeater Nested Repeater Nested Repeater Nested Repeater Nested Repeater Nested Repeater
Nested Repeater Nested Repeater
Nested Repeater
Go Back  Xtreme Visual Basic Talk > > > Nested Repeater


Reply
 
Thread Tools Display Modes
  #1  
Old 12-31-2006, 11:36 AM
abev107 abev107 is offline
Junior Contributor
 
Join Date: Oct 2003
Location: New York
Posts: 225
Default Nested Repeater


As you can see I am totally lost. I thought I could force asp.net to act like classic asp but it just doesn't work that way.

I am trying to create a nested repeater. I have master records, then detail records for the master records.

-Master
--Detail
--Detail
--Detail
-Master
etc..

The master and detail record source will be from two different SqlDataSource's.

I need a starting point. What creates the Parent and Child field property to link the Master and Detail?


Code:
<form id="form1" runat="server">
    <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:fauxBookieConnectionString %>"
            SelectCommand="SELECT [EventID], [EventName], convert(varchar, [eventdatetime], 108) AS TIME, [EventDateTime], [MinBet] FROM [tblEvents] WHERE [EventDateTime] > GetDate() AND [eventDateTime]< GetDate()+1">
        </asp:SqlDataSource>
        
        <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" >
            <HeaderTemplate>
                <table width="100%">
                    <tr bgcolor="gray">
                        <td width="100%" colspan="4"><h4>
                            Events for
                            <%=FormatDateTime(Now(), DateFormat.ShortDate)%></h4>
                        </td>
                    </tr>
                    <tr>
                        <td width=25%>Opponent</td><td width=25%>Money Line</td><td width=25%>Spread</td><td width=25%>Score</td>
                    </tr>
                </table>
            </HeaderTemplate>
            <ItemTemplate>
                <table width="100%">
                    <tr>
                        <td width="100%" colspan="4">
                        <%# DataBinder.Eval(Container.DataItem, "Time") %>
                            <a href="<%# DataBinder.Eval(Container.DataItem, "EventID") %>">
                                <%#DataBinder.Eval(Container.DataItem, "EventName")%>
                            </a>
                        </td>
                     </tr>
                    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:fauxBookieConnectionString %>"
                        SelectCommand="SELECT * FROM [tblOutcomes] WHERE ([EventID] = 10000)">
                    </asp:SqlDataSource>
                    <asp:Repeater ID="Repeater2" runat="server" DataSourceID="SqlDataSource2">
                    <ItemTemplate>
                    <tr><td width=100% colspan=4>
                    <%# DataBinder.Eval(Container.DataItem, "Team") %>
                    <%# Databinder.Eval(container,"Parent.Parent.DataItem")%>
                    </td></tr>
                    </ItemTemplate>
                    </asp:Repeater>
                     <tr>
                        <td width="25%">
                            safe</td>
                        <td width="25%">
                            safe</td>
                        <td width="25%">
                            safe</td>
                        <td width="25%">
                            safe</td>
                    </tr>
                </table>
            </ItemTemplate>
            <SeparatorTemplate>
                <br />
                -------<br />
            </SeparatorTemplate>
        </asp:Repeater>
</div>
    </form>
__________________
Vor lauter Bäumen den Wald nicht sehen.
Reply With Quote
  #2  
Old 12-31-2006, 04:59 PM
wayneph's Avatar
waynephNested Repeater wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

Quote:
Originally Posted by abev107 View Post
As you can see I am totally lost. I thought I could force asp.net to act like classic asp but it just doesn't work that way.
In many cases you can "force" asp.net to work like classic asp, but I've never found a reason to do so...

Here is a link to an ASP.NET 2.0 Nested Repeater sample: http://www.asp.net/learn/dataaccess/....aspx?tabid=63

I haven't set one up using 2.0 yet, and I know there are quite a few changes from 1.1. I think the key is going to be setting up the parameter on your internal SQLDataSource that is Bound from your outer data source.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #3  
Old 01-02-2007, 10:06 AM
abev107 abev107 is offline
Junior Contributor
 
Join Date: Oct 2003
Location: New York
Posts: 225
Default

wayne thanks for the response. I am still just as lost but I did come across something while searching.

It appears it is possible to nest gridviews? If so it seems much simpler. Do you have any experience with this?

I need:

-Master record
--Detail1 --Detail2
--Detail1 --Detail2
-Master record
--Detail1 --Detail2
..etc

thanks
__________________
Vor lauter Bäumen den Wald nicht sehen.
Reply With Quote
  #4  
Old 01-02-2007, 01:40 PM
wayneph's Avatar
waynephNested Repeater wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

Nesting Repeaters and Nesting GridViews will work just the same. My guess is that to get the formatting you're looking for, you'll want to use a Repeater as the primary object, with a GridView inside of it.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #5  
Old 01-03-2007, 08:52 AM
abev107 abev107 is offline
Junior Contributor
 
Join Date: Oct 2003
Location: New York
Posts: 225
Default

Quote:
Originally Posted by wayneph View Post
Nesting Repeaters and Nesting GridViews will work just the same. My guess is that to get the formatting you're looking for, you'll want to use a Repeater as the primary object, with a GridView inside of it.
Thanks wayne.

I am still in the process of figuring out the easiest way to do it. I keep holding myself up because I am trying to understand why MS couldn't make a Parent and Child property that linked the two repeaters, instead of going in to long drawn out code to link them that I have no idea how to create

Even better, why couldn't you just have the WHERE of the sql data source of the detail repeater = the Primary Key of the master repeater and just fire everytime it repeats?
__________________
Vor lauter Bäumen den Wald nicht sehen.
Reply With Quote
  #6  
Old 01-03-2007, 01:28 PM
wayneph's Avatar
waynephNested Repeater wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

Quote:
Originally Posted by abev107 View Post
Even better, why couldn't you just have the WHERE of the sql data source of the detail repeater = the Primary Key of the master repeater and just fire everytime it repeats?
You sort of can...

Here is one line of code from the link I posted above.
HTML Code:
<asp:Parameter Name="CategoryID" Type="Int32" DefaultValue='<%# Eval("CategoryID")' />
That will go into the SelectParameters of the nested DataSource. Their sample uses a ObjectDataSource, but the principle will be the same for an Access or SQL DataSource as well.

Since it's in the ItemTemplate, Eval("CategoryID") will get evaluated for each item in the Repeater.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #7  
Old 01-04-2007, 10:51 AM
abev107 abev107 is offline
Junior Contributor
 
Join Date: Oct 2003
Location: New York
Posts: 225
Default

thanks again wayne.

I have sort of abandoned the nested repeater in favor of the nested gridview. I have followed the instructions here.

I have the output almost the way I like it. The master gridview displays all the records like it should, but the detail gridview shows ALL records when it should be just showing which records are linked to the master records.

In the detail gridview, I set up databinding in the user control (Eval "EventID") but it doesn't change the output.

What specifically binds the master to the detail? Do I need code behind? I am trying to develop in asp.net 2.0 (vb) and it seems like there are so many other versions that only add to my confusion.
__________________
Vor lauter Bäumen den Wald nicht sehen.
Reply With Quote
  #8  
Old 01-04-2007, 04:59 PM
wayneph's Avatar
waynephNested Repeater wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

He actually didn't show the code to bind the main grid to the user control. What I'd do is add a Property to the UserControl, and pass the id in that way.

HTML Code:
<uc1:MyNestedGrid ID="NestedDetails" runat="Server" ParentID='<%# Eval("ID") %>' />
And then in the usercontrol's code behind...
Code:
Public WriteOnly Property ParentID() As Integer Set(ByVal value As Integer) YourSQLDataSource.SelectParameters(0).DefaultValue = value End Set End Property

(This assumes that the first parameter in the DataSource is the ID to be passed to the query.)
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #9  
Old 01-05-2007, 12:21 PM
abev107 abev107 is offline
Junior Contributor
 
Join Date: Oct 2003
Location: New York
Posts: 225
Default

Thanks again wayne - especially for being patient.

I added the elements you suggested in the previous post.

I am still getting *all* of the results in the inner gridview. My inner grid has a sql data source where its "Select * From...". I assume this is where the problem comes in?

It seems to me that I cannot use a "Select *...", that I should be specifying within that inner grid "select" some type of "where".

I played with adding "Select * from table where column = ParentID()" but that didn't work. I am not even sure I had the syntax correct.

Hopefully I need just one more nudge
__________________
Vor lauter Bäumen den Wald nicht sehen.
Reply With Quote
  #10  
Old 01-05-2007, 04:43 PM
wayneph's Avatar
waynephNested Repeater wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

On the Inner Data Source you do need a WHERE clause. WHERE ParentID = @ParentID or something like that.

Then you'll have to create a Select Parameters collection in your DataSoruce.
HTML Code:
<selectparameters>
  <asp:parameter name="ParentID" DefaultValue="0" />
</selectparameters>
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #11  
Old 01-07-2007, 03:02 PM
abev107 abev107 is offline
Junior Contributor
 
Join Date: Oct 2003
Location: New York
Posts: 225
Default

Thanks for all your help, Wayne.

For whatever reason, this example clicked with me.

I have no idea why the other examples didn't work for me; could be me, could be them.
__________________
Vor lauter Bäumen den Wald nicht sehen.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Nested Repeater
Nested Repeater
Nested Repeater Nested Repeater
Nested Repeater
Nested Repeater
Nested Repeater Nested Repeater Nested Repeater Nested Repeater Nested Repeater Nested Repeater Nested Repeater
Nested Repeater
Nested Repeater
 
Nested Repeater
Nested Repeater
 
-->