0

enter image description here

I want to bind the CourseFee[] array to repeater. I want to bind Amount and CourseFeeType.Descr in my repeater. How do I bind it?

Chris Barlow
  • 3,274
  • 4
  • 31
  • 52
Kishan Gajjar
  • 1,120
  • 3
  • 22
  • 43
  • have a look at this question **http://stackoverflow.com/questions/487318/using-an-asp-net-repeater-with-an-array** which might help you – huMpty duMpty Mar 12 '12 at 17:43
  • This is a array of class..I want to bind the fee structures in the repeater..I am getting is CourseFee[] array... – Kishan Gajjar Mar 12 '12 at 17:51

1 Answers1

2

Sample Class

public class Order
{
    public CourceFeeType FeeType;
    public int Amount;
    public int CourseFee;

    public void AddFeeTypeDetails(CourceFeeType Fees)
    {
        FeeType = new CourceFeeType();
        FeeType.Code = Fees.Code;
        FeeType.Desc = Fees.Desc;
    }

    // Nested class
    public class CourceFeeType
    {
        public String Code;
        public String Desc;
    }
}

Sample Form Load Code

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        List<Order> List = new List<Order>();

        Order OrderObj = new Order();
        Order.CourceFeeType Fees = new Order.CourceFeeType();
        Fees.Code = "1";
        Fees.Desc = "w2s";
        OrderObj.Amount = 1;
        OrderObj.AddFeeTypeDetails(Fees);

        List.Add(OrderObj);

        OrderObj = new Order();
        OrderObj.Amount = 2;
        Fees = new Order.CourceFeeType();
        Fees.Code = "2";
        Fees.Desc = "w22s";
        OrderObj.AddFeeTypeDetails(Fees);

        List.Add(OrderObj);

        rpt.DataSource = List;
        rpt.DataBind();
    }

}

Repeater Item Bound Data Event Code

protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        Label lbl = (Label)e.Item.FindControl("lblDescription");
        lbl.Text = ((Order)e.Item.DataItem).FeeType.Desc;

        Label lblAmount = (Label)e.Item.FindControl("lblAmount");
        lblAmount.Text = ((Order)e.Item.DataItem).Amount.ToString();
    }
}

Sample HTML

<asp:Repeater ID="rpt" runat="server" OnItemDataBound="rpt_ItemDataBound">
    <HeaderTemplate>
        <table>
            <tr>
                <td>
                    Amount
                </td>
                <td>
                    Description
                </td>
            </tr>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td>
                <asp:Label ID="lblAmount" runat="server"></asp:Label>
            </td>
            <td>
                <asp:Label ID="lblDescription" runat="server"></asp:Label>
            </td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>
Pankaj
  • 9,749
  • 32
  • 139
  • 283