Binding a generic list to a repeater - ASP.NET

前端 未结 4 1902
悲&欢浪女
悲&欢浪女 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:22

    You may want to create a subRepeater.

    
      
        <%# Eval("Name") %>
      
    
    

    You can also cast your fields

    <%# ((ArrayFields)Container.DataItem).Fields[0].Name %>
    

    Finally you could do a little CSV Function and write out your fields with a function

    <%# GetAsCsv(((ArrayFields)Container.DataItem).Fields) %>
    
    public string GetAsCsv(IEnumerable fields)
    {
      var builder = new StringBuilder();
      foreach(var f in fields)
      {
        builder.Append(f);
        builder.Append(",");
      }
      builder.Remove(builder.Length - 1);
      return builder.ToString();
    }
    

提交回复
热议问题