Dynamically generate Repeater

Source: Internet
Author: User

 

 

Code

1 Public   Class Mytemplate: itemplate
2 {
3 System. Web. UI. webcontrols. listitemtype templatetype;
4 Static   Int Titlelength;
5 Public Mytemplate (system. Web. UI. webcontrols. listitemtype type)
6 {
7 Templatetype = Type;
8 }
9
10 Public   Void Instantiatein (system. Web. UI. Control container)
11 {
12 Placeholder pH =   New Placeholder ();
13 Label Item1 =   New Label ();
14 Hyperlink item2 =   New Hyperlink ();
15 Label item3 =   New Label ();
16 Item1.id =   " Item1 " ;
17 Item2.id =   " Item2 " ;
18
19 Switch (Templatetype)
20 {
21 Case Listitemtype. header:
22 Ph. Controls. Add ( New Literalcontrol ( " <Table border = \ " 0 \ " > " ));
23 Break ;
24 Case Listitemtype. item:
25 Ph. Controls. Add ( New Literalcontrol ( " <Tr> <TD> " ));
26 Ph. Controls. Add (item2 );
27 Ph. Controls. Add ( New Literalcontrol ( " </TD> <TD> " ));
28 Ph. Controls. Add (Item1 );
29 Ph. Controls. Add ( New Literalcontrol ( " </TD> </tr> " ));
30 Ph. databinding + =   New Eventhandler (item_databinding );
31 Break ;
32 Case Listitemtype. alternatingitem:
33 Ph. Controls. Add ( New Literalcontrol ( " <Tr> <TD> " ));
34 Ph. Controls. Add (item2 );
35 Ph. Controls. Add ( New Literalcontrol ( " </TD> <TD> " ));
36 Ph. Controls. Add (Item1 );
37 Ph. Controls. Add ( New Literalcontrol ( " </TD> </tr> " ));
38 Ph. databinding + =   New Eventhandler (item_databinding );
39 Break ;
40 Case Listitemtype. footer:
41 Ph. Controls. Add ( New Literalcontrol ( " </Table> " ));
42 Break ;
43 }
44 Container. Controls. Add (ph );
45 }
46
47 Static   Void Item_databinding ( Object Sender, system. eventargs E)
48 {
49 Placeholder pH = (Placeholder) sender;
50 Repeateritem ri = (Repeateritem) Ph. namingcontainer;
51 Datetime item1value = (Datetime) databinder. eval (Ri. dataitem, " Publishdate " );
52 String item2value = (String) databinder. eval (Ri. dataitem, " Title " );
53 (Label) Ph. findcontrol ( " Item1 " ). Text = Item1value. tostring ( " Yyyy-mm-dd " );
54 }
55 }

 

 

 

 

 

Code

1 Repeater noticerepeater =   New Repeater ();
2 List < Democlass > Noticelist =   New List < Democlass > ();
3
4
5 Noticerepeater. headertemplate =   New Mytemplate (listitemtype. header );
6 Noticerepeater. itemtemplate =   New Mytemplate (listitemtype. item );
7 Noticerepeater. alternatingitemtemplate =   New Mytemplate (listitemtype. alternatingitem );
8 Noticerepeater. footertemplate =   New Mytemplate (listitemtype. footer );

 

 

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.