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 );