Work With Web Controls

Not only can you add literals to a table cell, but you can also add other controls. The full page for this example is available on the CD.

TYPE THIS:

void Page_Load(Object sender, EventArgs e) { string[] sGoalList = {"Hike the Appalachian

Trail",

"Give $1 million to worthwhile causes"};

int iRows = sGoalList.GetUpperBound(0) + 1;

TableRow trGoals = new TableRow(); TableCell tcGoals = new TableCell(); tcGoals.Controls.Add (new

LiteralControl(sGoalList[i]));

trGoals.Cells.Add(tcGoals); TableCell tcGoal2s = new

TableCell() CheckBox())

tcGoal2s.Controls.Add(new trGoals.Cells.Add(tcGoal2s); Tablei.Rows.Add(trGoals);

RESULT:

A table that contains a list of goals with a checkbox next to each.

£ Save the file and request it from the Web server.

■ A table with the contents of your array appears.

Process each row with a for loop.

— Create a new HTMLTableRow for each row.

—± Process each cell in the row with a for loop.

Create a new HTMLTableCell for each cell and add the value in the array to the cell.

£ Save the file and request it from the Web server.

Note: See pages 20 to 25 for instructions on saving a file to the Web server and then requesting the file using the IIS Admin.

■ A table with the contents of your array appears.

Was this article helpful?

0 0

Post a comment