0

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>
                    <asp: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.

Jack Marchetti
  • 15,536
  • 14
  • 81
  • 117
Kashif
  • 14,071
  • 18
  • 66
  • 98

2 Answers2

0

Do you have some other reference that includes a Repeater class in its namespace?

Perhaps try casting it to System.Web.UI.WebControls.Repeater.

nekno
  • 19,177
  • 5
  • 42
  • 47
  • He is casting it by wrapping it in (Repeater) – Jack Marchetti Aug 11 '11 at 14:14
  • He's casting it to a `Repeater`, but is it resolving to `System.Web.UI.WebControls.Repeater` or `MyCustomRepeater.Repeater`? Things in the `System.Data` namespace have conflicts all the time. – nekno Aug 11 '11 at 18:51
-1

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")

Jack Marchetti
  • 15,536
  • 14
  • 81
  • 117
  • thanks, I could not get it that how does .DataSource knows that I have checked ItemType or not? By the way I have tried it but same error. – Kashif Aug 10 '11 at 21:44
  • -1; while you're correct, this has nothing to do with the **compile-time** error the OP is seeing. – Adam Maras Aug 10 '11 at 21:44
  • @Adam - good point, I saw he wasn't checking for ItemType and immediately jumped to that. I think I solved his issue, unless he just has typos in his markup. – Jack Marchetti Aug 10 '11 at 21:57