Binding a generic list to a repeater - ASP.NET

前端 未结 4 1915
悲&欢浪女
悲&欢浪女 2020-12-04 19:28

I am trying to bind a List to a repeater. I have converted the list into an array by using the ToArray() method and now have a arr

4条回答
  •  被撕碎了的回忆
    2020-12-04 20:20

    It is surprisingly simple...

    Code behind:

    // Here's your object that you'll create a list of
    private class Products
    {
        public string ProductName { get; set; }
        public string ProductDescription { get; set; }
        public string ProductPrice { get; set; }
    }
    
    // Here you pass in the List of Products
    private void BindItemsInCart(List ListOfSelectedProducts)
    {   
        // The the LIST as the DataSource
        this.rptItemsInCart.DataSource = ListOfSelectedProducts;
    
        // Then bind the repeater
        // The public properties become the columns of your repeater
        this.rptItemsInCart.DataBind();
    }
    

    ASPX code:

    
      
        
        
        
    Product Name Product Description Product Price
    <%# Eval("ProductName") %> <%# Eval("ProductDescription")%> <%# Eval("ProductPrice")%>

    I hope this helps!

提交回复
热议问题