How do I put a user control into a table?

  • Thread starter Thread starter Robin Bonin
  • Start date Start date
R

Robin Bonin

I have a user control that create a product thumbnail and details. I am
working on aother user control that I will pass some variables like # of
columns and rows to display these thumbnails. I'm having trouble dynamicly
adding a new thumbnail control to my table.

Dim newCell As New TableCell
Dim newRow As New TableRow
Dim productThumb As New htmlBlock_ProductThumb ' This is my
usercontrol

newCell.Controls.Add(productThumb) ' Not
sure how to add it to the table cell
newRow.Cells.Add(newCell)

FeaturedProducts.Rows.Add(newRow)
 
Robin,

When you load a user control it's slightly different than creating a dynamic
control.

newCell.Controls.Add(LoadControl([Path to your user control as String])

And you won't need to create the user control before this so delete the
line:

Dim productThumb As New htmlBlock_ProductThumb ' This is my usercontrol

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
Found the answer to my question.
for reference...

Dim newCell As New TableCell
Dim newRow As New TableRow
Dim productThumb As New Control

productThumb =
LoadControl("../userControls/htmlBlock_ProductThumb.ascx")
CType(productThumb, htmlBlock_ProductThumb).itemSku = "1001A"
newCell.Controls.Add(productThumb)

newRow.Cells.Add(newCell)
FeaturedProducts.Rows.Add(newRow)


Robin Bonin said:
This worked great, I just have one problem.
I need to pass atleast one paramater to this control for the item ID to be
dsiplayed.

I declared the control as follows.
productThumb = LoadControl("../userControls/htmlBlock_ProductThumb.ascx")

but the public properties are not exposed though the productThumb control. I
tried passing a variable
through the querry string but I got an error. control needs to end with a
.ascx.



S. Justin Gengo said:
Robin,

When you load a user control it's slightly different than creating a dynamic
control.

newCell.Controls.Add(LoadControl([Path to your user control as String])

And you won't need to create the user control before this so delete the
line:

Dim productThumb As New htmlBlock_ProductThumb ' This is my usercontrol

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche


Robin Bonin said:
I have a user control that create a product thumbnail and details. I am
working on aother user control that I will pass some variables like # of
columns and rows to display these thumbnails. I'm having trouble dynamicly
adding a new thumbnail control to my table.

Dim newCell As New TableCell
Dim newRow As New TableRow
Dim productThumb As New htmlBlock_ProductThumb ' This is my
usercontrol

newCell.Controls.Add(productThumb)
'
Not
sure how to add it to the table cell
newRow.Cells.Add(newCell)

FeaturedProducts.Rows.Add(newRow)
 
Back
Top