Thursday, March 22, 2012

Strongly typed datasets and nested repeaters

I have a strongly typed dataset that returns two tables - "items" and
"itemdetails". In the strongly-typed dataset designer, I've created a link
(relationship) between the two tables based on a foreign key.

I want to put them into a nested repeater, but I'm having problems finding a
"nice" way of doing it.

Can someone please point me in the direction of a tutorial or best practice
to achieve this?

Thanks in advance,

Duncanassign the "Items" table to the outter repeater, then in the
OnItemDataBound event handler:

switch (e.Item.ItemType){
case ListItemType.Item: case ListItemType.AlternatingItem:
Repeater ir = e.Item.FindControl("rptInnerRepeater")
ir.DataSource =
((DataRowView)e.Item.DataItem).CreateChildView("ItemDetailDataRelation");
ir.DataBind();
}

hope that helps
Thanks for your reply; I saw this example on the web, but I'm unsure where
the ItemDetailDataRelation comes from. I tried all the relationship names
that were in the strongly-typed dataset designer, but they gave an error.

I got the impression that if you were doing it between two datatables, that
would be the name of the Relations.Add(... but I couldn't seem to create a
programatic relationship between two fields in a strongly typed dataset.

Duncan

"bfking" <bfking@.gmail.com> wrote in message
news:1112879887.227421.298170@.g14g2000cwa.googlegr oups.com...
> assign the "Items" table to the outter repeater, then in the
> OnItemDataBound event handler:
> switch (e.Item.ItemType){
> case ListItemType.Item: case ListItemType.AlternatingItem:
> Repeater ir = e.Item.FindControl("rptInnerRepeater")
> ir.DataSource =
> ((DataRowView)e.Item.DataItem).CreateChildView("ItemDetailDataRelation");
> ir.DataBind();
> }
> hope that helps
The relation is set up in the dataset.

something like
_myDataSet.Relations.Add("Users_Results", _myDataSet.TableA.UsersNameColumn,
_myDataSet.TableB.UsersNameColumn);

where _myDataSet is your strongly typed DataSet.
in your nested Repeater you would then do something like this:

<asp:repeater id="_reportoutput" Runat="server"
...templates

//nested repeater
<asp:repeater id="_nextstuff" Runat="server" DataSource='<%#
GetChildRelation(Container.DataItem,"Users_Results")%>'
with the following in your code behind:

public static DataView GetChildRelation(object dataItem, string relation)
{
DataRowView drv = dataItem as DataRowView;
if (drv != null)

return drv.CreateChildView(relation);
else
return null;
}

MattC
"Duncan Welch" <dunc@.ntpcl.f9.co.uk> wrote in message
news:usyUFl3OFHA.984@.TK2MSFTNGP10.phx.gbl...
> Thanks for your reply; I saw this example on the web, but I'm unsure where
> the ItemDetailDataRelation comes from. I tried all the relationship names
> that were in the strongly-typed dataset designer, but they gave an error.
> I got the impression that if you were doing it between two datatables,
> that
> would be the name of the Relations.Add(... but I couldn't seem to create a
> programatic relationship between two fields in a strongly typed dataset.
> Duncan
> "bfking" <bfking@.gmail.com> wrote in message
> news:1112879887.227421.298170@.g14g2000cwa.googlegr oups.com...
>> assign the "Items" table to the outter repeater, then in the
>> OnItemDataBound event handler:
>>
>> switch (e.Item.ItemType){
>> case ListItemType.Item: case ListItemType.AlternatingItem:
>> Repeater ir = e.Item.FindControl("rptInnerRepeater")
>> ir.DataSource =
>> ((DataRowView)e.Item.DataItem).CreateChildView("ItemDetailDataRelation");
>> ir.DataBind();
>> }
>>
>> hope that helps
>>

0 comments:

Post a Comment