Ch02
{
[ToolboxData("<{0}:tablecustomcontrol runat=server>{0}:tablecustomcontrol>")]
public class TableCustomControl : Control
{
// Properties to access dimensions of HTML table
// New property declaration syntax in C# 3.0
public int X { get; set; }
public int Y { get; set; }
66 CHAPTER 2 ?– ENCAPSULATING FUNCT IONALITY IN A SP.NET
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
RenderHeader(writer);
RenderTable(writer, X, Y);
}
private void RenderHeader(HtmlTextWriter writer)
{
// write just
writer.WriteBeginTag("h3");
// write >
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write("TableCustomControl");
// write
writer.WriteFullBeginTag("br");
writer.Write("X:" + X.ToString() + " ");
writer.WriteLine("Y:" + Y.ToString() + " ");
// write
writer.WriteEndTag("h3");
}
private void RenderTable(HtmlTextWriter writer, int xDim, int yDim)
{
// write
writer.AddAttribute(HtmlTextWriterAttribute.Border, "1");
writer.RenderBeginTag(HtmlTextWriterTag.Table);
for (int y = 0; y < yDim; y++)
{
// write
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
for (int x = 0; x < xDim; x++)
{
// write writer.AddAttribute(HtmlTextWriterAttribute.
Pages:
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|