Error accessing a nested repeater in parent ItemDataBound event
Error:
'Repeater' does not contain a definition for 'DataSource' and no extension method 'DataSource' accepting a first argument of type 'Repeater' could be found (are you missing a using directive or an assembly reference?)
Code:
protected void rptIndicator_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Repeater r2 = (Repeater)e.Item.FindControl("rptActivity");
r2.DataSource = dt; //Error on this line.
r2.DataBind();
}
Markup:
<asp:Repeater ID="rptIndicator" runat="server" OnItemDataBound="rptIndicator_ItemDataBound">
<ItemTemplate>
<asp:Repeater ID="rptActivity" runat="server">
<ItemTemplate>
<as开发者_C百科p:Repeater ID="rptActivityData" runat="server"></asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
Can you please help. Why .DataSource
is giving me error here.
Thanks.
Do you have some other reference that includes a Repeater
class in its namespace?
Perhaps try casting it to System.Web.UI.WebControls.Repeater
.
First, you need to check the ItemType or else you'll be back wondering why you're getting a runtime error.
switch (e.Item.ItemType) {
case ListItemType.Item:
case ListItemType.AlternatingItem:
Repeater r2 = (Repeater)e.Item.FindControl("rptActivity");
r2.DataSource = dt; //Error on this line.
r2.DataBind();
}
I'm guessing this is a typo, but your markup lists the repeater as "rptActivityData" but in your code you are looking for FindControl("rptActivity")
精彩评论