Paritosh Paritosh - 3 months ago 18
ASP.NET (C#) Question

SelectMethod get data from a parent control

I'm using .Net 4.5, model binding and currently have a repeater, which contains another repeater.

<asp:Repeater ID="rptADivisions" runat="server" ItemType="abc.Division" SelectMethod="rptADivisions_GetData">
<%#: Item.DivisionName %>
<asp:Repeater ID="rptDOfficials" runat="server" ItemType="abc.DOfficial" SelectMethod="rptDOfficials_GetData">
<p><%#: Item.FullName %></p>
<small><%#: Item.Position %></small>
<hr />

I'm able to populate the 1st repeater (rptADivisions), but how would I get the second one to work? I need to have the second one get access to the Did, which is contained in the top repeater (rptADivisions) Item (abc.Divison). I've tried setting the SelectMethod for the second repeater as

public IEnumerable<abc.DOfficial> rptDOfficials_GetData([Control("rptADivisions")] string DidFilter)

but that doesn't seem to work, the DidFilter is always set to null.


I don't have VS at hand but the repeater, like most databound controls, should have something like DataBound or RowDataBound event you can hook and be able to execute some code when a row is bound to its counterpart from the datasource.

In the event, you should be able to write c# code to access the repeater (FindControl("rptDOfficials")) and get the item you actually bind to. Having these two will allow you to build a set of items and bind declaratively by calling

.DataSource = your set of items

At least this is how you do nested datagrids, listviews, I hope this works with the repeater too.