Solved

ASP.net Dynamically adding a table with a solid row color

Posted on 2014-03-30
3
818 Views
Last Modified: 2014-03-30
Hi

I am dynamically adding the table below to an ASP.net web page using the code
further down. I want the rows to have a bottom row with a solid row color and border line that runs right through. I generated the second image in Excel, and this shows
how I want the table to look. How do I adjust the VB.net code to achieve this. Thanks


1
2

  Function oTableReport() As Table
        Try

            Dim rowCnt As Integer
            ' Current row count
            Dim rowCtr As Integer
            ' Total number of cells (columns).
            Dim cellCtr As Integer
            ' Current cell counter.
            Dim cellCnt As Integer
            Dim Table1 As New Table
            rowCnt = 2
            cellCnt = 3
            Table1.BorderWidth = 1
            Table1.BorderColor = Drawing.Color.Black
            Table1.BorderStyle = BorderStyle.Solid
            Table1.GridLines = GridLines.None

            For rowCtr = 1 To rowCnt
                Dim tRow As New TableRow()
                tRow.BackColor = Drawing.Color.Aqua
                For cellCtr = 1 To cellCnt
                    Dim tCell As New TableCell()
                    tCell.Text = "Row " & rowCtr & ", Cell " & cellCtr
                    'tCell.BackColor = Drawing.Color.White
                    tCell.ForeColor = Drawing.Color.Blue
                    ' Add new TableCell object to row.
                    tRow.Cells.Add(tCell)
                Next
                ' Add new row to table.
                Table1.Rows.Add(tRow)
            Next
            Return Table1
        Catch ex As Exception
            MsgBox(ex.Message & " rew33")
        End Try
    End Function
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 39965651
Very hard to do it in code behind alone.
Please remove the following code from your sample above:
            Table1.BorderWidth = 1
            Table1.BorderColor = Drawing.Color.Black
            Table1.BorderStyle = BorderStyle.Solid
            Table1.GridLines = GridLines.None

Open in new window

and add the following  CSS rules to your mark-up head section as follows:
<head>
<style>
table,th,td
{
border-bottom:1px solid black;
border-spacing: 0px;
}
</style>
</head>

Open in new window

where:
CSS border-spacing removes cell spacing when the value is 0px.
CSS border-bottom creates the bottom border on every header and cell of your table.
0
 
LVL 26

Accepted Solution

by:
Alan Warren earned 500 total points
ID: 39965766
Hi murbro,
Try something like this:
<%@ Page Language="VB" %>

<!DOCTYPE html>

<script runat="server">
  Function oTableReport() As Table
    oTableReport = Nothing

    Try

      Dim rowCnt As Integer
      ' Current row count
      Dim rowCtr As Integer
      ' Total number of cells (columns).
      Dim cellCtr As Integer
      ' Current cell counter.
      Dim cellCnt As Integer
      Dim Table1 As New Table

      rowCnt = 2
      cellCnt = 3

      Table1.GridLines = GridLines.None

      For rowCtr = 1 To rowCnt
        Dim tRow As New TableRow()

        If rowCtr < rowCnt Then

          For cellCtr = 1 To cellCnt
            Dim tCell As New TableCell()
            tCell.Text = "Row " & rowCtr & ", Cell " & cellCtr

            ' Add new TableCell object to row.
            tRow.Cells.Add(tCell)
          Next

        Else ' it's the last row

          For cellCtr = 1 To cellCnt
            Dim tCell As New TableCell()

            tCell.Text = "Row " & rowCtr & ", Cell " & cellCtr
            tCell.CssClass = "lastrow"  ' <<<== apply lastrow style to cells in the last row

            ' Add new TableCell object to row.
            tRow.Cells.Add(tCell)
          Next

        End If

        ' Add new row to table.
        Table1.Rows.Add(tRow)
      Next
      Return Table1
    Catch ex As Exception
      ' MsgBox(ex.Message & " rew33")
      System.Diagnostics.Debug.WriteLine(ex.Message)
    End Try

  End Function

  Protected Sub Button1_Click(sender As Object, e As EventArgs)
    Me.Controls.Add(oTableReport())
  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <style type="text/css">
    table {
      border: none;
      border-collapse:collapse;
      border-spacing:0;

    }
      table tr {
        border: none;
      }
      table td {
        border: none;
      }

    table td.lastrow {
      border-left:none;
      border-right:none;
      border-top:1px solid black;
      border-bottom:3px double black; /*need about 3px to render double line border*/
      background-color:lightblue;
    }
  </style>

    <title>Q_28400693</title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <asp:Literal ID="Literal1" runat="server"></asp:Literal>
      <asp:button ID="Button1" runat="server" text="Create Table" OnClick="Button1_Click" />   
    </div>
  </form>
</body>
</html>

Open in new window

Looks like:
Q_28400693
Respectfully yours,
Alan
0
 

Author Closing Comment

by:Murray Brown
ID: 39965803
Thanks very much Alan
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

691 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