Repeater Control : Can it work with different data sources?

  • Thread starter Emma Middlebrook
  • Start date
E

Emma Middlebrook

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
 
C

Cowboy \(Gregory A. Beamer\)

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!
|
*************************************************
 
E

Emma Middlebrook

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

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
 
C

Cowboy \(Gregory A. Beamer\)

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 <table> and all header tags
<th>something</th> in 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!
|
*************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top