By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,719 Members | 1,046 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,719 IT Pros & Developers. It's quick & easy.

Repeater Control : Can it work with different data sources?

P: n/a
Hi there,

I've been trying to implement a repeater control in an ASP.NET 2 page
but I can't seem to get the layout exactly how I want and I'm not sure
if it's something that I am doing wrong or maybe the repeater control
doesn't have the capabilities...?

The page needs to display a custom number of sections that appear the
same but have different data..

E.g. Like a bank statement..

Label: Transactions for date ....

A table showing the transactions.

Then ideally a row at the bottom totalling the columns in the grid.

I've implemented a repeater control putting the first label in the
header, then the item template holds all the transactions. The total
row was put in the footer template..

Unfortunately, I can only see a way to have one block. This needs to
be dynamic as I'm told at display time how many blocks of transactions
I need to output onto the page...

Here's the aspx code I've come up with so far...

<asp:Repeater ID="siteSummary" runat="server"
DataSourceID="sitesDS" OnItemDataBound="ItemBound">
<HeaderTemplate>
<table width="100%">
<tr>
<asp:Label ID="itemHeader" width="100%"
BackColor="#C25E00" ForeColor="White" Text="Transactions"
runat="server"/>
</tr>
<tr>
<th>Description</th>
<th>Total</th>
</tr>
</HeaderTemplate>

<ItemTemplate>
<tr>
<td><%#DataBinder.Eval(Container.DataItem,
"Description").ToString()%></td>
<td><%#DataBinder.Eval(Container.DataItem,
"Total").ToString()%></td>
</tr>
</ItemTemplate>

<FooterTemplate>
<tr>
<td></td>
<td>Todo: total?</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>

Perhaps there is a better way of doing this that I am not familiar
with?

Many thanks,

Emma

Nov 6 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
The main body of the Repeater repeats for every row in your result set. And,
as you control the HTML, you do not have to attempt to bind multiple
recordsets to a single Repeater to get header and footer, as you can create
the table header and footer outside of the Repeater.

Does this answer your concern?

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
"Emma Middlebrook" <e.***********@googlemail.comwrote in message
news:11**********************@o38g2000hse.googlegr oups.com...
Hi there,

I've been trying to implement a repeater control in an ASP.NET 2 page
but I can't seem to get the layout exactly how I want and I'm not sure
if it's something that I am doing wrong or maybe the repeater control
doesn't have the capabilities...?

The page needs to display a custom number of sections that appear the
same but have different data..

E.g. Like a bank statement..

Label: Transactions for date ....

A table showing the transactions.

Then ideally a row at the bottom totalling the columns in the grid.

I've implemented a repeater control putting the first label in the
header, then the item template holds all the transactions. The total
row was put in the footer template..

Unfortunately, I can only see a way to have one block. This needs to
be dynamic as I'm told at display time how many blocks of transactions
I need to output onto the page...

Here's the aspx code I've come up with so far...

<asp:Repeater ID="siteSummary" runat="server"
DataSourceID="sitesDS" OnItemDataBound="ItemBound">
<HeaderTemplate>
<table width="100%">
<tr>
<asp:Label ID="itemHeader" width="100%"
BackColor="#C25E00" ForeColor="White" Text="Transactions"
runat="server"/>
</tr>
<tr>
<th>Description</th>
<th>Total</th>
</tr>
</HeaderTemplate>

<ItemTemplate>
<tr>
<td><%#DataBinder.Eval(Container.DataItem,
"Description").ToString()%></td>
<td><%#DataBinder.Eval(Container.DataItem,
"Total").ToString()%></td>
</tr>
</ItemTemplate>

<FooterTemplate>
<tr>
<td></td>
<td>Todo: total?</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>

Perhaps there is a better way of doing this that I am not familiar
with?

Many thanks,

Emma

Nov 6 '07 #2

P: n/a
On 6 Nov, 13:37, "Cowboy \(Gregory A. Beamer\)"
<NoSpamMgbwo...@comcast.netNoSpamMwrote:
The main body of the Repeater repeats for every row in your result set. And,
as you control the HTML, you do not have to attempt to bind multiple
recordsets to a single Repeater to get header and footer, as you can create
the table header and footer outside of the Repeater.

Does this answer your concern?

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************" Emma Middlebrook" <e.middlebr...@googlemail.comwrote in message

news:11**********************@o38g2000hse.googlegr oups.com...
Hi there,
I've been trying to implement a repeater control in an ASP.NET 2 page
but I can't seem to get the layout exactly how I want and I'm not sure
if it's something that I am doing wrong or maybe the repeater control
doesn't have the capabilities...?
The page needs to display a custom number of sections that appear the
same but have different data..
E.g. Like a bank statement..
Label: Transactions for date ....
A table showing the transactions.
Then ideally a row at the bottom totalling the columns in the grid.
I've implemented a repeater control putting the first label in the
header, then the item template holds all the transactions. The total
row was put in the footer template..
Unfortunately, I can only see a way to have one block. This needs to
be dynamic as I'm told at display time how many blocks of transactions
I need to output onto the page...
Here's the aspx code I've come up with so far...
<asp:Repeater ID="siteSummary" runat="server"
DataSourceID="sitesDS" OnItemDataBound="ItemBound">
<HeaderTemplate>
<table width="100%">
<tr>
<asp:Label ID="itemHeader" width="100%"
BackColor="#C25E00" ForeColor="White" Text="Transactions"
runat="server"/>
</tr>
<tr>
<th>Description</th>
<th>Total</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#DataBinder.Eval(Container.DataItem,
"Description").ToString()%></td>
<td><%#DataBinder.Eval(Container.DataItem,
"Total").ToString()%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td></td>
<td>Todo: total?</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
Perhaps there is a better way of doing this that I am not familiar
with?
Many thanks,
Emma
Hi there,

Thanks a lot, I don't think I have fully understood the header, item
and footer parts of the repeater.. I have removed the header and
footer portions...

Thanks,

Emma

Nov 6 '07 #3

P: n/a
The repeater, as a control, is made up of templates for rows of data (and
alternating rows, if you want to, for example, have different shading on
every second row) and then a header and footer template.

The norm, when creating a table, is to put the <tableand all header tags
<th>something</thin the header template. You then put all of the footer
information in the footer template, which may just be </table>

For every row in the bound dataset (output of DataSource control, etc.), you
get a row in the repeater that looks like the row template (or row and
alternating row templates).

If you have data for the header from one data source, for the footer from
another and for the main repeating sections from another, you are better to
move the <table><th... stuff out of the repeater and bind separately. Same
with the footer. Then, the repeater is just creating rows.

One caveat. You may have to fill the empty template (no records) in the
repeater to avoid a bad looking table. Other than that, it is a sound
method.

Does that help a bit more?

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
"Emma Middlebrook" <e.***********@googlemail.comwrote in message
news:11*********************@y42g2000hsy.googlegro ups.com...
On 6 Nov, 13:37, "Cowboy \(Gregory A. Beamer\)"
<NoSpamMgbwo...@comcast.netNoSpamMwrote:
>The main body of the Repeater repeats for every row in your result set.
And,
as you control the HTML, you do not have to attempt to bind multiple
recordsets to a single Repeater to get header and footer, as you can
create
the table header and footer outside of the Repeater.

Does this answer your concern?

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*********************************************** **
| Think outside the box!
|
************************************************* "Emma Middlebrook"
<e.middlebr...@googlemail.comwrote in message

news:11**********************@o38g2000hse.googleg roups.com...
Hi there,
I've been trying to implement a repeater control in an ASP.NET 2 page
but I can't seem to get the layout exactly how I want and I'm not sure
if it's something that I am doing wrong or maybe the repeater control
doesn't have the capabilities...?
The page needs to display a custom number of sections that appear the
same but have different data..
E.g. Like a bank statement..
Label: Transactions for date ....
A table showing the transactions.
Then ideally a row at the bottom totalling the columns in the grid.
I've implemented a repeater control putting the first label in the
header, then the item template holds all the transactions. The total
row was put in the footer template..
Unfortunately, I can only see a way to have one block. This needs to
be dynamic as I'm told at display time how many blocks of transactions
I need to output onto the page...
Here's the aspx code I've come up with so far...
<asp:Repeater ID="siteSummary" runat="server"
DataSourceID="sitesDS" OnItemDataBound="ItemBound">
<HeaderTemplate>
<table width="100%">
<tr>
<asp:Label ID="itemHeader" width="100%"
BackColor="#C25E00" ForeColor="White" Text="Transactions"
runat="server"/>
</tr>
<tr>
<th>Description</th>
<th>Total</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#DataBinder.Eval(Container.DataItem,
"Description").ToString()%></td>
<td><%#DataBinder.Eval(Container.DataItem,
"Total").ToString()%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td></td>
<td>Todo: total?</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
Perhaps there is a better way of doing this that I am not familiar
with?
Many thanks,
Emma

Hi there,

Thanks a lot, I don't think I have fully understood the header, item
and footer parts of the repeater.. I have removed the header and
footer portions...

Thanks,

Emma

Nov 6 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.