Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Laying out controls in CreateChildControls()

Status
Not open for further replies.

markknowsley

Programmer
Aug 30, 2005
152
GB
I've got some controls in a web part, and I want to try to lay them out a in a table.

So I've got the following code:

Code:
public override void CreateChildControls() 
{
    lblLabel = new Label();
    lblLabel.Text = "Some Text";
    this.Controls.Add(lblLabel);

    txtSearch = new TextBox();
    this.Controls.Add(txtSearch);
}

and so on. I found reference to Table, TableRow and TableCell on the Microsoft website and presume that i could use these html-style to lay out my controls, but if I do
Code:
Table myTable = new Table();
TableRow myRow = new TableRow();
myTable.Rows.Add(myRow);
TableCell myCell = new TableCell();
myRow.Cells.Add(myCell);
myCell.Controls.Add(lblLabel);

then the Label just vanishes if I add the control to the cell after I've added the control to the collection, and has no effect if I add the add the control to the cell before I've added it to the collection.

Has anyone else successfully achieved this - and can you tell me how?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top