How do I bind a dictionary to a repeater?

Source: Internet
Author: User
Tags listsource
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 %>...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.