1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 using System.Web.UI;
6 using System.Web.UI.WebControls.WebParts;
7 using System.Web.UI.HtmlControls;
8
9 using System.Collections;
10
11 using Eallies.WebParts.Hello;
12
13 namespace Eallies.WebParts.Associated
14 {
15 public class List : WebPart, IPostBackEventHandler
16 {
17 private IList _Items = new ArrayList();
18
19 private HtmlTableCell _HtmlTableCell = new HtmlTableCell();
20
21 public List()
22 {
23 this.GetItems();
24 }
25
26 protected override void CreateChildControls()
27 {
28 this.Controls.Add(new LiteralControl("<table>" + "\n"));
29 this.Controls.Add(new LiteralControl(" <tr>" + "\n"));
30 this.Controls.Add(this._HtmlTableCell);
31 this.Controls.Add(new LiteralControl(" </tr>" + "\n"));
32 this.Controls.Add(new LiteralControl("</table>" + "\n"));
33
34 if (this.Page.IsPostBack == false) this.AddRows();
35 }
36
37 protected override void OnLoad(EventArgs e)
38 {
39 base.OnLoad(e);
40
41 if (this.Page.IsPostBack == true) this.AddRows();
42 }
43
44 protected override void Render(HtmlTextWriter writer)
45 {
46 base.Render(writer);
47 }
48
49 private void GetItems()
50 {
51 this._Items.Add("Row 1");
52 this._Items.Add("Row 2");
53 this._Items.Add("Row 3");
54 this._Items.Add("Row 4");
55 this._Items.Add("Row 5");
56 }
57
58 private void AddRows()
59 {
60 for (int i = 0; i < _Items.Count; i++)
61 {
62 this._HtmlTableCell.Controls.Add(new LiteralControl("<table>" + "\n"));
63 this._HtmlTableCell.Controls.Add(new LiteralControl(" <tr>" + "\n"));
64 this._HtmlTableCell.Controls.Add(new LiteralControl(" <td style=\"cursor:hand\" onclick=\"" + this.Page.ClientScript.GetPostBackEventReference(this, this._Items[i].ToString()) + "\">" + this._Items[i].ToString() + "</td>" + "\n"));
65 this._HtmlTableCell.Controls.Add(new LiteralControl(" </tr>" + "\n"));
66 this._HtmlTableCell.Controls.Add(new LiteralControl("</table>" + "\n"));
67 }
68 }
69
70 #region IPostBackEventHandler Members
71
72 public void RaisePostBackEvent(string eventArgument)
73 {
74 for (int i = 0; i < WebPartManager.WebParts.Count; i++)
75 {
76 if (WebPartManager.WebParts[i].Title == "Instance")
77 {
78 Instance instance = (Instance)WebPartManager.WebParts[i];
79 instance.Text = eventArgument;
80 }
81 }
82 }
83
84 #endregion
85 }
86 }