Binding a generic list to a repeater - ASP.NET

前端 未结 4 1899
悲&欢浪女
悲&欢浪女 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 19:57

    Code Behind:

    public class Friends
    {
        public string   ID      { get; set; }
        public string   Name    { get; set; }
        public string   Image   { get; set; }
    }
    
    protected void Page_Load(object sender, EventArgs e)
    {
            List  friendsList = new List();
    
            foreach (var friend  in friendz)
            {
                friendsList.Add(
                    new Friends { ID = friend.id, Name = friend.name }    
                );
    
            }
    
            this.rptFriends.DataSource = friendsList;
            this.rptFriends.DataBind();
    }
    

    .aspx Page

    
                
                    
                        
                        
    ID Name
    <%# Eval("ID") %> <%# Eval("Name") %>

提交回复
热议问题