As mentioned in msdn, the data source object that can be used as a data binding control must inherit and implement the ienumerable or ilistsource interface.
The dictionary class obviously inherits and implements the ienumerable interface. So how do I bind a dictionary object to controls such as repeater?
--------------------
The following is an example (segment)
1 Public Class Dictest: Page
2 {
3 Protected Repeater namelist;
4 Dictionary < String , String > Listsource = New Dictionary < String , String > ();
5 Public Dictest ()
6 {
7 Listsource. Add ( " Mc1 " , " Mcjeremy " );
8 Listsource. Add ( " MC2 " , " Mcjeremy " );
9 Listsource. Add ( " MC3 " , " Mcjeremy " );
10 Listsource. Add ( " Mc4 " , " Mcjeremy " );
11 }
12 Private Void Page_load ( Object Sender, eventargs E)
13 {
14Namelist. datasource=Listsource;
15Namelist. databind ();
16}
17 Override Protected Void Oninit (eventargs E)
18 {
19Initialize ();
20Base. Oninit (E );
21}
22 Private Void Initialize ()
23 {
24This. Load+ =NewEventhandler (This. Page_load );
25}
26 }
:
--------------------
In the foreground, data is bound, as shown in the following (segment) 1 < Table >
2 < ASP: repeater ID = " Namelist " Runat = " Server " >
3 < Itemtemplate >
4 < Tr >
5 < TD > Key: <% # Eval ( " Key " ) %> </ TD >
6 < TD > Value: <% # Eval ( " Value " ) %> </ TD >
7 </ Tr >
8 </ Itemtemplate >
9 </ ASP: Repeater >
10 </ Table >
------------
If arraylist and other classes are used,
When binding, use <% # container. dataitem %>...