开发者

Repeater and public array as NOT datasource.

开发者 https://www.devze.com 2023-03-24 03:02 出处:网络
I want to using two dataSources with repeater. One is binded to dataSource property so my question is is that possible to f.ex. to also repeat some array of string as public p开发者_Python百科roperty?

I want to using two dataSources with repeater. One is binded to dataSource property so my question is is that possible to f.ex. to also repeat some array of string as public p开发者_Python百科roperty?


It is possible to bind to a property of your datasource that is also a collection. For example:

class Person
{
   List<Phone> Phones { get; set; }
   string Name { get; set; }
}

class Phone
{
   string Number { get; set; }
}

 void Page_Load(...)
 {
     List<Person> people = GetPeople();
     peopleRepeater.DataSource = people;
     peaopleRepeater.DataBind();
 }

aspx page

 <asp:Repeater ID="peopleRepeater" runat="server">
     <ItemTemplate>
        Name : <%# Eval("Name") %>
        Phones: <br/>
       <asp:Repeater ID="phonesRepeater" runat="server" DataSource='<%# (Container.DataItem as Person).Phones %>'>
           <ItemTemplate>
              <%# Eval("Number") %> <br />
           </ItemTemplate>

       </asp:Repeater>

     </ItemTemplate>
  </asp:Repeater>


Most ASP.NET Data controls only will bind to a single data source at a time. It is possible to have nested controls that can be bound to multiple data sources. Some 3rd party controls such as RadGridView are designed to handle multiple datasource binding (e.g. hierachical).

0

精彩评论

暂无评论...
验证码 换一张
取 消