Using table tags with custom controls

K

kashif456

Hi,
I am adding textbox and label control programatically and need some
assistance in getting these to show up in a table. Here's my code:

For i = 0 To dv.Count - 1
SaleAttributeTextField = "Sale_Attribute_" &
dv.Table.Rows(i)("SalesAttributeID")
SaleAttributeLalbel = "Sale_Attribute_Label_" &
dv.Table.Rows(i)("SalesAttributeID")

Dim textBox As TextBox
textBox = New TextBox
textBox.Enabled = EditMode
textBox.ID = SaleAttributeTextField.ToString
Dim AttribLabel As Label
AttribLabel = New Label
AttribLabel.ID = SaleAttributeLalbel.ToString
AttribLabel.Text =
dv.Table.Rows(i)("SalesAttributeDisplayName")

'''note: Need to add <tr><td> tags here
Controls.Add(AttribLabel)
''' Need to add </td></tr><tr><td> tags here
Controls.Add(textBox)
'' need to add </td></tr> tags here

filter = "SalesAttributeID=" &
dv.Table.Rows(i)("SalesAttributeID")
dv2.RowFilter = filter
If dv2.Count() > 0 Then
textBox.Text =
dv2.Table.Rows(rowCounter)("SalesAttributeValue")
rowCounter = rowCounter + 1
Else
textBox.Text = ""
End If

Next
 
N

~~~ .NET Ed ~~~

What you need to do there is do something like this (not all code provided
for shortness!)

HtmlTable table = new HtmlTable();
table.Border = 0; // Modify other attributes as well if you want
HtmlTableRow tr = new HtmlTableRow();
HtmlTableCell td = new HtmlTableCell();
td.Controls.Add(AttribLabel); // adds your label control on the
left cell
tr.Cells.Add(td); // and that cell gets added
to the current row
td = new HtmlTableCell();
td.Controls.Add(textBox); // same with the text box
tr.Cells.Add(td);
table.Rows.Add(tr);
this.Controls.Add(table);

Notice that your controls are being added to the respective cells and then
the table gets added to your
composite control's control collection thus creating a hierarchy of
controls.

Anyway, that is how I neatly put child controls in a table when I develop a
composite control. And sorry it is in C#, i just find VB too messy and too
verbose for clarity.

Hope that helps,
Emil
 
K

kashif456

Emil,
Thanks for your help. The above suggestion worked out great and
I was able to modify all my code to work except when it comes to
working with checkboxlist and placeholders. I am still having trouble
adding them to tableCell. If you can comment on this as, I would
appreciate it. Here's my code (It's currently writing out the table
with response.write())

For i = 0 To storeCount - 1
If Not storeID = StoreView.Table.Rows(i)("storeID")
Then
Response.Write("<tr><td>")
Response.Write("<br>")
Response.Write("</td></tr>")

storeID = StoreView.Table.Rows(i)("storeID")
Response.Write("<tr><td>")

Response.Write(StoreView.Table.Rows(i)("StoreName"))
Response.Write("</td></tr>")

Response.Write("<tr><td>")
Response.Write("<br>")
Response.Write("</td></tr>")

End If
Response.Write("<tr><td>")
Response.Write(StoreView.Table.Rows(i)("FirstName") & "
" & StoreView.Table.Rows(i)("LastName"))
Response.Write("</td>")

Dim CheckBoxList As CheckBoxList
CheckBoxList = New CheckBoxList

CheckBoxList.RepeatDirection =
RepeatDirection.Horizontal
CheckBoxList.RepeatLayout = RepeatLayout.Table
CheckBoxList.AutoPostBack = False
Dim CheckBoxListName As String
CheckBoxListName = "SeuciryCheckBox_" & _
StoreView.Table.Rows(i)("CustomerID") &
"_" _
& StoreView.Table.Rows(i)("StoreID")
CheckBoxList.ID = CheckBoxListName.ToString
CheckBoxList.DataSource = SecurityCodeDS

CheckBoxList.DataTextField = "SecurityDescription"
CheckBoxList.DataValueField = "SecurityLevel"
CheckBoxList.DataBind()


this is what I need to modify... I get errors such as
(checkbox needs to be part of a form ) or it just won't show up...

GroupPlaceHolder.Controls.Add(CheckBoxList)
Dim TableCell As New HtmlTableCell

'''' This didn't work ...
'TableCell.Controls.Add(CheckBoxList)
If SetDefaults Then
SetUserRights(CheckBoxList, SecurityDS,
SecurityCodeDS, _

StoreView.Table.Rows(i)("CustomerID"), _

StoreView.Table.Rows(i)("StoreID"))
End If

Response.Write("</td></tr>")
Next

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top