Repeater Question

G

GD

I need to bind my repeater to a DataSet for which the number of columns
is always different (cross-tab report). However, I need to exlude an Id
column from displaying on the Repeater. As shown below, I'm not
specifying each column to display so I can't simply not include that
column. I also can't physically remove that column from the DataTable
because it is the parent column in a DataRelation.

Here's what my Repeater looks like on the aspx side (I got a lot of
help on this from Joshua Mitts on this group)

<asp:Repeater ID="rptCompanies" Runat="server"
OnItemDataBound="rptCompanies_OnItemDataBound">
<ItemTemplate>
<tr>
<asp:Repeater ID="rptCompanyActivity" Runat="server">
<ItemTemplate>
<td><%# (object) Container.DataItem %></td>
</ItemTemplate>
</asp:Repeater>
</tr>
</asp:Repeater>

On Page_Load I'm doing this:

rptCompanies.DataSource = dsRpt.Tables["Company"].Rows;
rptCompanies.DataBind();

and on rptCompanies_OnItemDataBound

DataRow drCompany = (DataRow) e.Item.DataItem;
object [] oCompanyCols = drCompany.ItemArray;
Repeater rptCompanyActivity = (Repeater)
e.Item.FindControl("rptCompanyActivity");
rptCompanyActivity.DataSource = oCompanyCols;
rptCompanyActivity.DataBind();


I think the key to this is going to be in setting the DataSource of
rptCompanies. However, I don't think I can use the DataTable.Select
method to select certain column names, but just to filter my Rows.
 
K

Kevin Spencer

This certainly *is* a Repeater question. I've seen it repeated at least 3
times today!

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
 
K

Kevin Spencer

I guess it's just the title that's been repeated!

In that case, GD, let me take a crack at it:

Your suspicions are well-founded. All of the filtering that is done on
DataTables and DataViews is by row, not by column. In addition, a
DataColumnCollection doesn't have a Remove method. So, I think your only
resort would be to create a new DataTable, copy only the columns you want
into it, and then copy the row values for those columns into the rows that
you will have to create for the new DataTable, and use that.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
 

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

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top