?
Solved

Tables with a TableCell

Posted on 2005-04-29
11
Medium Priority
?
438 Views
Last Modified: 2008-03-10
I am using the asp:table command and have created a number of tablerows and tablecells within these tablerows. This all works fine within my code-behind. I would however like to be able to add a table into one of my tablecells just like I can within HTML <table><tr><td><table><tr> and so on. If someone has a sample or suggestions on how to do this, I would be most appreciative. I am having trouble finding any documentation on this.

        Dim TRD1 As New TableRow
        Dim TCD As New TableCell
        Dim TCE As New TableCell
        Dim TCF As New TableCell

        TCD.HorizontalAlign = HorizontalAlign.Left
        TCD.BorderColor = Color.Blue
        TCD.BorderWidth = Unit.Point(2)
        TCD.Width = Unit.Pixel(20)
        TCD.Font.Name = "Arial"
        TCD.Font.Size = FontUnit.Point(7)
        TCD.Font.Bold = False
        TCD.ForeColor = Color.FromName("#732928")
        TCD.Text = "A"
        TCE.BorderColor = Color.Red
        TCE.BorderWidth = Unit.Point(2)
        TCE.HorizontalAlign = HorizontalAlign.Left
        TCE.Width = Unit.Pixel(40)
        TCE.Font.Name = "Arial"
        TCE.Font.Size = FontUnit.Point(9)
        TCE.Font.Bold = True
        TCE.ForeColor = Color.Blue
        TCE.Text = "B"
        TCF.Width = Unit.Pixel(60)
        TRD1.Controls.Add(TCD)
        TRD1.Controls.Add(TCE)
        TRD1.Controls.Add(TCF)
        tblCore.Rows.Add(TRD1)


<table border="0" cellspacing="0" cellpadding="0">
      <tr>
            <td bgColor="#f3f3f3">
                  <asp:Table ID="tblCore" BorderColor="black" BorderWidth=2 Runat="server"></asp:Table>
            </td>
      </tr>
</table>


0
Comment
Question by:Plecoman
  • 4
  • 4
  • 3
11 Comments
 
LVL 2

Expert Comment

by:Odyssey122
ID: 13898027
response.write ("<table>")
response.write ("<tr>")
response.write ("<td>")
response.write ("</td>")
response.write ("</tr>")
response.write ("</table>")

Ody
0
 
LVL 2

Expert Comment

by:Odyssey122
ID: 13898056
or

response.write("<table><tr><td></td></tr></table>")

Ody
0
 

Author Comment

by:Plecoman
ID: 13898431
Thank you, but I am looking to use this in the code-behind without the Response.write command as shown in the sample code provided.
Any thoughts in this case?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Expert Comment

by:Odyssey122
ID: 13898467
I having problems understanding what your asking for then...sorry.  Could you explain a little more in detail.

Ody
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13899302
very simple example


<%@ Import Namespace="System.Data" %>
<%@ Page Language="VB" Debug="True" %>
<HTML>
<HEAD>
<Script Language="vb" Runat="Server">

Dim ds As DataSet(), _
      dt As DataTable, _
      dt2 As DataTable, _
      dc As DataColumn, _
      dr As DataRow, _
      PKColumn(1) As DataColumn
      
Public Sub Page_Load(s As Object, e As EventArgs)
      If Not IsPostBack Then
            BindData()
      End If
      
End Sub

Public Sub BindData()
      Dim ds As DataSet(), _
      dt As DataTable, _
      dt2 As DataTable, _
      dc As DataColumn, _
      dr As DataRow, _
      'PKColumn(1) As DataColumn

      dt=New DataTable()
      dc=New DataColumn("ItemID", GetType(Integer))
      dc.AutoIncrement=True
      dc.AutoIncrementSeed=0
      dc.AutoIncrementStep=1
      dc.Unique=True
      dt.Columns.Add(dc)
      'PKColumn(0)=dc
      'dt.PrimaryKey=PKColumn
      
      dc=New DataColumn("Item Name", GetType(String))
      dt.Columns.Add(dc)
      
      dc=New DataColumn("Quantity", GetType(Integer))
      dt.Columns.Add(dc)
      
      dc=New DataColumn("Price", GetType(Decimal))
      dt.Columns.Add(dc)
      
      dr=dt.NewRow()
      dr("Item Name")="Data Item 1"
      dr("Quantity")=1
      dr("Price")=19.99
      dt.Rows.Add(dr)
      
      dr=dt.NewRow()
      dr("Item Name")="Data Item 2"
      dr("Quantity")=1
      dr("Price")=49.99
      dt.Rows.Add(dr)
      
      dr=dt.NewRow()
      dr("Item Name")="Data Item 3"
      dr("Quantity")=1
      dr("Price")=69.99
      dt.Rows.Add(dr)
      
      dr=dt.NewRow()      
      dr("Item Name")="Data Item 4"
      dr("Quantity")=1
      dr("Price")=19.99
      dt.Rows.Add(dr)
      
      dr=dt.NewRow()
      dr("Item Name")="Data Item 5"
      dr("Quantity")=1
      dr("Price")=49.99
      dt.Rows.Add(dr)
      
      dr=dt.NewRow()
      dr("Item Name")="Data Item 6"
      dr("Quantity")=1
      dr("Price")=69.99
      dt.Rows.Add(dr)      
      
      dr=dt.NewRow()      
      dr("Item Name")="Data Item 7"
      dr("Quantity")=1
      dr("Price")=19.99
      dt.Rows.Add(dr)
      
      dr=dt.NewRow()
      dr("Item Name")="Data Item 8"
      dr("Quantity")=1
      dr("Price")=49.99
      dt.Rows.Add(dr)
      
      dr=dt.NewRow()
      dr("Item Name")="Data Item 9"
      dr("Quantity")=1
      dr("Price")=69.99
      dt.Rows.Add(dr)            
      
      cart.DataSource=dt
      cart.DataBind()
      
      Dim total As Decimal
      total=dt.Compute("Sum(Price)", Nothing)
      lblmsg.Text="Order Total: " & total.ToString()
      
      Session("dt")=dt
End Sub

Public Sub dg_Paging(o As Object, e As DataGridPageChangedEventArgs)
      cart.CurrentPageIndex=e.NewPageIndex
      BindData()
End Sub

Public Sub Delete(s As Object, e As EventArgs)
      Dim item,arr
      Dim      i As Integer=0, _
            row As DataRow
            
      dt2=Session("dt")
      arr=Request.Form("ItemID")
      arr=arr.split(",")
      For i=UBound(arr) To 0 Step -1
            dt2.Rows(arr(i)).Delete()
      Next
      i=0
      For Each row In dt2.Rows
            row("ItemID")=i
            i+=1
      Next
      cart.DataSource=dt2
      cart.DataBind()
      Session("dt")=dt2
End Sub

</Script>
<TITLE></TITLE>
</HEAD>
<BODY>

<form runat="server">
      <asp:datagrid id="cart" runat="server" autogeneratecolumns="false" width="300"
            allowpaging="true"
            pagesize="9"
            pagerstyle-mode="numericpages"
            onpageindexchanged="dg_Paging">
            <columns>
                  <asp:templatecolumn>
                        <itemtemplate>
                              <input type="checkbox" value="<%#Container.DataItem("ItemID")%>" name="ItemID">
                        </itemtemplate>
                  </asp:templatecolumn>
                  <asp:boundcolumn datafield="Item Name" headertext="Item Name" />
                  <asp:boundcolumn datafield="Quantity" headertext="Quantity" />
                  <asp:boundcolumn datafield="Price" headertext="Price" />
            </columns>
      </asp:datagrid>
      <br>
      <asp:label id="lblmsg" runat="server" />
      <br>
      <asp:button id="btn1" text="Delete" onclick="Delete" runat="server" />
</form>

</BODY>
</HTML>
0
 

Author Comment

by:Plecoman
ID: 13899401
Thank you for your feedback thus far. I am trying to put an asp:table within an asp:table through code behind. In the orginal sample I provided, I created a table (not a datatable), added tablerows and tablecells. What I am looking for now, is how to put a table within a table like the html example I provided (without using response write). I do realize I could put it in the TEXT field within the tablecell, but am looking to see if there is something better.
0
 
LVL 13

Accepted Solution

by:
davidlars99 earned 250 total points
ID: 13899423
ok then, how about this?


<%@ Page language="VB" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>

<html>
    <head>
        <script runat="server">
            Private Sub Page_Load(sender As Object, e As System.EventArgs)
                ' Create a TableItemStyle object that can be
                ' set as the default style for all cells
                ' in the table.
                Dim tableStyle As New TableItemStyle()
                tableStyle.HorizontalAlign = HorizontalAlign.Center
                tableStyle.VerticalAlign = VerticalAlign.Middle
                tableStyle.Width = Unit.Pixel(100)
                ' Create more rows for the table.
                Dim i As Integer
                For i = 2 To 9
                    Dim tempRow As New TableRow()
                    Dim j As Integer
                    For j = 0 To 2
                        Dim tempCell As New TableCell()
                        tempCell.Text = "(" & i & "," & j & ")"
                        tempRow.Cells.Add(tempCell)
                    Next j
                    Table1.Rows.Add(tempRow)
                Next i

                ' Apply the TableItemStyle to all rows in the table.
                Dim r As TableRow
                For Each r In  Table1.Rows
                    Dim c As TableCell
                    For Each c In  r.Cells
                        c.ApplyStyle(tableStyle)
                    Next c
                Next r

                ' Create a header for the table.
                Dim header As New TableHeaderCell()
                header.RowSpan = 1
                header.ColumnSpan = 3
                header.Text = "Table of (x,y) Values"
                header.Font.Bold = true
                header.BackColor = Color.CornflowerBlue
                header.HorizontalAlign = HorizontalAlign.Center
                header.VerticalAlign = VerticalAlign.Middle

                ' Add the header to a new row.
                Dim headerRow As New TableRow()
                headerRow.Cells.Add(header)

                ' Add the header row to the table.
                Table1.Rows.AddAt(0, headerRow)
            End Sub
        </script>
    </head>

    <body>
        <form runat="server">
            <h1>TableCell Example</h1>
            <asp:table id="Table1" runat="server" CellPadding="3" CellSpacing="3">
                <asp:TableRow>
                    <asp:TableCell Text="(0,0)"></asp:TableCell>
                    <asp:TableCell Text="(0,1)"></asp:TableCell>
                    <asp:TableCell Text="(0,2)"></asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell Text="(1,0)"></asp:TableCell>
                    <asp:TableCell Text="(1,1)"></asp:TableCell>
                    <asp:TableCell Text="(1,2)"></asp:TableCell>
                </asp:TableRow>
            </asp:table>
        </form>
    </body>
</html>
0
 

Author Comment

by:Plecoman
ID: 13912097
Thank you for the sample, I am not however seeing where a table has been added within a tablecell within the sample provided.

Here is what I am running now, just wondering if there was something cleaner.

            Dim tblCore As New Table
            Dim WHR1 As New TableRow

            Dim modHeading as string = "<table><tr><td>xxxx</td></tr></table>"

            Dim WHR1e As New TableCell
            WHR1e.HorizontalAlign = HorizontalAlign.Left
            WHR1e.VerticalAlign = VerticalAlign.Bottom
            WHR1e.Font.Name = "Arial"
            WHR1e.Width = Unit.Pixel(200)
            WHR1e.ColumnSpan = 3
            WHR1e.Font.Size = FontUnit.Point(8)
            WHR1e.Font.Bold = True
            WHR1e.ForeColor = Color.Black
            WHR1e.Text = modHeading
            WHR1.Controls.Add(WHR1e)

            tblCore.Rows.Add(WHR1)
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13912223
>  I am not however seeing where a table has been added within a tablecell ....

you have it there already --> Dim modHeading as string = "<table><tr><td>xxxx</td></tr></table>"


> just wondering if there was something cleaner.

you can create another table using "Table Class" in the same fashion and append it to the existing one or you can create your own class inherited from WebControl and override it's "Publick Overrides Sub Render(ByVal w As HtmlTextWriter)" method to write out custom html

0
 

Author Comment

by:Plecoman
ID: 13934726
I am going to try working with this command, I will keep you posted
Table1.Rows[0].Cells[0].Controls.Add(new Table());
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 14179493
thank you very much for C-grade, You're not gonna get any help if you keep grading so poorly!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question