0

I have a user control that contains a repeater. I populate the datasource for the repeater (I have checked it contains data) but the repeater doesn't display any data. The control has been added to the page correctly.

 //aspx for user control
 <asp:Repeater runat="server">
        <HeaderTemplate><table>
        <%# Eval("Name") %>
 </HeaderTemplate>

 //C# for user control
 public object DataSource { get; set; }
 protected void Page_Load(object sender, EventArgs e)
    {
        this.DataSource = DataSet;
        this.DataBind();
    }

//C# (code behind of aspx page where I want to use the repater user control)
repeater.DataSource = DataSet.ToArray();
repeater.DataBind();

Any ideas why this isn't working?

2
  • <tr> and <td> tags are missing inside table Commented Sep 16, 2011 at 13:19
  • 2
    is this your real markup or just sloppy copying and pasting? Commented Sep 16, 2011 at 13:20

4 Answers 4

3

Try this way :

    <asp:Repeater ID="repeater1" runat="server"> 
            <HeaderTemplate>
                <table class="datatable fullwidthpercent"> 
                   <tr>
                       <td>Name</td>
                   </tr>
            </HeaderTemplate>
            <ItemTemplate>
                   <tr>
                       <td><%# Eval("Name") %></td> 
                   </tr>
               </table>
            </ItemTemplate>
            <FooterTemplate>
               </table>
            </FooterTemplate>
   </asp:Repeater> 

and also write repeater1.DataBind(); after assigning datasource property.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your reply, I added this. I used the debugger and the datasource is being populated for the user control and databind() is called but data is still not displayed.
I used the aspx from your answer. I think the problem might be with the data binding, do you need to bind it in the page load method of the user control or in the code behind of the file you want to use the user control in?
you need to bind it in user control only where you can access repeater1.
Thanks for your help - I didn't have an ID attribute for the reapeter user control. I added the following code to the repeater user control code behind: this.repeater1.DataSource = DataSource;
repeater1.DataBind(); Is what worked for me!
3

repeater.DataBind();

ASP.NET controls do not bind automatically.

1 Comment

DataBind() may need to be called, but I think OP also needs to use the ItemTemplate
2

HeaderTemplates, I believe, don't bind data, they only display static content. You have to put data to bind in the ItemTemplate or AlternatingItemTemplate.

I assume you omitted the DataBind statement from this, that needs to be called too.

1 Comment

I moved the Eval("datavalue") to the itemtemplate and bind is there I didn't include it in the question.
0
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        getdata();
    }

}
public void getdata()
{
    ds = objfun12.display();
    repeat12.DataSource = ds;
     repeat12.DataBind();

}

1 Comment

Please add some explanation of your answer and how it is relevant to the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.