Prev | Current Page 127 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"

Controls;
}
}
protected override void CreateChildControls()
{
Controls.Clear();
BuildHeader();
BuildTable(X, Y);
}
private void BuildHeader()
{
CHAPTER 2 ?–  ENCAPSULATING FUNCT IONALITY IN ASP.NET 71
StringBuilder sb = new StringBuilder();
sb.Append("TableCompCustomControl
");
sb.Append("X:");
sb.Append(X.ToString());
sb.Append(" ");
sb.Append("Y:");
sb.Append(Y.ToString());
sb.Append(" ");
HtmlGenericControl header = new HtmlGenericControl("h3");
header.InnerHtml = sb.ToString();
Controls.Add(header);
}
private void BuildTable(int xDim, int yDim)
{
HtmlTableRow row;
HtmlTableCell cell;
HtmlGenericControl content;
// create
table = new HtmlTable();
table.Border = 1;
for (int y = 0; y < Y; y++)
{
// create
row = new HtmlTableRow();
for (int x = 0; x < X; x++)
{
// create

cell = new HtmlTableCell();
cell.Attributes.Add("border", "1");
// create a
content = new HtmlGenericControl("span");
content.InnerHtml = "X:" + x.ToString() +
"Y:" + y.ToString();
cell.Controls.Add(content);
row.Cells.Add(cell);
}
table.Rows.Add(row);
}
Controls.Add(table);
}
}
}
72 CHAPTER 2 ?–  ENCAPSULATING FUNCT IONALITY IN A SP.NET
Composite custom controls typically do not override the Render() method.


Pages:
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139