Solved

looping thru gridview not acting as expected

Posted on 2009-05-05
3
265 Views
Last Modified: 2013-11-07
In vb.net/asp.net 2.0 I build this table from a gridview named gv:
(Code is simplified from actual)
Dim table1 As Table
Dim table2 As Table
 For Each grdItem As GridViewRow In gv.Rows
                        Dim row1 As New TableRow()
                        Dim cell1 As TableCell
                        cell1 = tbBPAddCell(row1, grdItem.Cells(0).Text, "center", "Style1", 4)
                        cell1 = tbBPAddCell(row1, grdItem.Cells(1).Text, "center", "Style1", 7, 2)
                        table1.Rows.Add(row1)
                        Me.Panel1.Controls.Add(table1)

                        Dim row2 As New TableRow()
                        Dim cell2 As TableCell
                        cell2= tbBPAddCell(row2, grdItem.Cells(2).Text, "center", "Style1", 4)
                        cell2= tbBPAddCell(row2, grdItem.Cells(3).Text, "center", "Style1", 7, 2)
                        table2.Rows.Add(row2)
                        Me.Panel1.Controls.Add(table1)
 Next

The problem lies in when the table built the first table is displayed as many times as there are rows and then the second table is displayed as many times as there are rows. Like this:
table1
table1
table2
table2

But! My goal is to display one table after another like this:
table1
table2
table1
table2

If the code worked like I thought it did I should get my desired results. I can't get it to work correctly with two separate tables. How can I loop thru this gridview to have my tables display one after another??? Please provide an example.
If it helps, here's the function called in the code snippit:
 

Public Function tbBPAddCell(ByVal row As TableRow, ByVal Contents As String, ByVal Align As String, ByVal CellType As String, ByVal ColSpan As Integer, Optional ByVal RSpan As Integer = 1, Optional ByVal Width As Integer = 0) As TableCell

        tbBPAddCell = New TableCell()

        tbBPAddCell.Font.Size = 9

        tbBPAddCell.Wrap = False

        tbBPAddCell.BorderColor = Drawing.Color.Black

        

        If CellType = "Style1" Then

            tbBPAddCell.Font.Size = 12

            tbBPAddCell.Wrap = True

            tbBPAddCell.ForeColor = Drawing.Color.Black

            tbBPAddCell.BorderStyle = BorderStyle.Solid

            tbBPAddCell.BorderColor = Drawing.Color.Black

            tbBPAddCell.BorderWidth = Unit.Pixel(1)

        End If
 

        tbBPAddCell.ColumnSpan = ColSpan

        tbBPAddCell.RowSpan = RSpan

        If Align = "left" Then

            tbBPAddCell.HorizontalAlign = HorizontalAlign.Left

        ElseIf Align = "center" Then

            tbBPAddCell.HorizontalAlign = HorizontalAlign.Center

        Else

            tbBPAddCell.HorizontalAlign = HorizontalAlign.Right

        End If

        tbBPAddCell.Text = Contents

        row.Cells.Add(tbBPAddCell)

    End Function

Open in new window

0
Comment
Question by:techpr0
  • 2
3 Comments
 
LVL 20

Expert Comment

by:informaniac
Comment Utility
I think a single table would suffice for you.

Instead of adding to two different tables table1 and table2. just keep on adding to table1

0
 

Author Comment

by:techpr0
Comment Utility
Thanks for the feedback informaniac. That worked in testing but the two "real" tables are totally different and extremely long and being able to do two separate tables would save me a ton of work. That's the goal of this post.
0
 

Accepted Solution

by:
techpr0 earned 0 total points
Comment Utility
Nevermind, it was obvious. If you add to the same table (by name) it's going to append to the table of the same name the next time it loops. I had to reinstanciate the table name each time by putting the table declaration within the for each loop.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now