how to use two List<> as datasource of a repeater at the same time asp.net -


i trying display data of 2 different list<> repeater. secondary list must displayed in column of table inside of repeater. both number of list<>'s items same.i happy if guys give me solution or method solving.

you concatenate 2 string lists object list so:

make new class has 2 strings properties (this can in current page code behind file if want should outside of page's class declaration - e.g. below end if page class):

class twostrings {     public string string1 { get; set; }     public string string2 { get; set; } } 

here sample code take 2 lists of strings (like have) , brings them in list of twostrings class.

list<string> list1 = new list<string>(); list<string> list2 = new list<string>();  //some sample data list1.add("1"); list2.add("one"); list1.add("2"); list2.add("two");  list<twostrings> twostringlist = new list<twostrings>();  //this assumimg both lists same length (int index = 0; index <= list1.count - 1; index++) {     twostrings ts = new twostrings();     ts.string1 = list1(index);     ts.string2 = list2(index);     twostringlist.add(ts); }  repeater1.datasource = twostringlist; repeater1.databind(); 

here's sample of repeater might like:

<asp:repeater id="repeater1" runat="server" >     <itemtemplate>         <tr>             <td>                 <asp:label runat="server" text='<%# eval("string1")%>' />             </td>             <td >                 <asp:label runat="server" text='<%# eval("string2")%>' />             </td>         </tr>         <br />     </itemtemplate> </asp:repeater> 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -