0

Totally new to webforms user controls, I am bit confused, on how to create a user control and fill some data on it.

for(int i = 0; i < Price.EpList.Count(); i++)
                        {

                            Price.EpList[i].Amount.ToString();
                            Price.EpList[i].Code.ToString();
                            Price.EpList[i].Desc.ToString();
                            Price.EpList[i].ID.ToString();

                        }

EpList is a list that contains info that i want to display in webpage on tabular format with checkboxes on each row.

1
  • Where are you calling this sample? Commented May 2, 2012 at 16:30

1 Answer 1

3

Take a look at the Repeater Control. You don't have to loop through your list, you just bind the list to the repeater and define the html template you want for each repeated item.

http://www.w3schools.com/aspnet/aspnet_repeater.asp


EDIT: That article uses Visual Basic, so here's the C# translation:

Assuming this repeater:

<asp:Repeater runat="server" ID="uxEpList">
<ItemTemplate>
<%--Html goes here--%>
<%# Eval("Amount")%>
<%# Eval("Code")%>
<%# Eval("Desc")%>
<%# Eval("ID")%>   
</ItemTemplate>
</asp:Repeater>

In code behind:

uxEpList.DataSource = Price.Eplist;
uxEpList.DataBind();

If you need to nest a repeater inside another one (using the Desc property from your comment) you can do it like this, by setting the DataSource property declaratively (note the single quotes):

<asp:Repeater runat="server" ID="uxEpList">
<ItemTemplate>
    <asp:Repeater Datasource='<%# Eval("Desc")%>' runat="server">
    <ItemTemplate>
    //etc...
Sign up to request clarification or add additional context in comments.

3 Comments

thanks for your help, i forgot to mention Price.EpList[i].Desc[j].Item;Price.EpList[i].Desc[j].ID;Price.EpList[i].Desc[j].Unit; there is nested list inside EpList how to display it in repeater
You can nest repeaters, too. I'll update the code with an example.
Not sure what you mean by that. Are you trying to get the data using the nested repeater's DataSource property? Is it binding correctly? It might be best to start a new question, so you can post your new code.

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.