Using table tags with custom controls

Discussion in 'ASP .Net Building Controls' started by kashif456@gmail.com, Mar 31, 2005.

  1. Guest

    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
     
    , Mar 31, 2005
    #1
    1. Advertising

  2. 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

    <> wrote in message
    news:...
    > 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
    >
     
    ~~~ .NET Ed ~~~, Apr 1, 2005
    #2
    1. Advertising

  3. Guest

    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
     
    , Apr 2, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ranganath

    Custom Tags within Custom Tags.

    Ranganath, Oct 17, 2003, in forum: Java
    Replies:
    2
    Views:
    486
    Ranganath
    Oct 21, 2003
  2. Mike
    Replies:
    3
    Views:
    965
    Michael Borgwardt
    Jan 9, 2004
  3. A. Brinkmann
    Replies:
    2
    Views:
    1,114
    A. Brinkmann
    Apr 16, 2004
  4. koslows
    Replies:
    0
    Views:
    543
    koslows
    May 12, 2005
  5. Dave
    Replies:
    0
    Views:
    463
Loading...

Share This Page