Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Using table tags with custom controls

Reply
Thread Tools

Using table tags with custom controls

 
 
kashif456@gmail.com
Guest
Posts: n/a
 
      03-31-2005
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

 
Reply With Quote
 
 
 
 
~~~ .NET Ed ~~~
Guest
Posts: n/a
 
      04-01-2005
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

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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
>



 
Reply With Quote
 
 
 
 
kashif456@gmail.com
Guest
Posts: n/a
 
      04-02-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP Custom Tags as attribute values for other custom tags Dave Java 0 08-14-2006 02:21 PM
JSF tags enclosed in custom JSP tags? koslows Java 0 05-12-2005 08:09 PM
Evaluating struts tags inside my own custom tags... A. Brinkmann Java 2 04-16-2004 07:44 AM
JSP newbie - use include, custom tags, standard tags - or what? Mike Java 3 01-09-2004 09:30 AM
Custom Tags within Custom Tags. Ranganath Java 2 10-21-2003 06:14 AM



Advertisments