2 Replies - 149 Views - Last Post: 22 February 2019 - 11:17 AM Rate Topic: -----

#1 DarenR   User is offline

  • D.I.C Lover

Reputation: 598
  • View blog
  • Posts: 3,884
  • Joined: 12-January 10

issue adding items to grid view by column

Posted 22 February 2019 - 07:46 AM

i am trying to add database to columns and cells that are created dynamically -- column width is 4 with a cell in each column.
the rows will be determined by the number of rows in the database / 4 + mod (in case row numbers arent divisible by 4)

what it is doing is creating all the cells in each row instead of 1 data point per cell per column row

in the attached image #1 should be in 1st row #2 in second row #3 in 3rd row



 For rowCtr = 1 To rowCnt

                Dim tRow As New TableRow()
                'For cellCtr = 1 To cellCnt
                '    Dim tCell As New TableCell()
                For Each item As DataRow In dsDataSet.Tables(0).Rows
                        Dim urlName As String = String.Empty
                        Dim cnt As Integer = 0
                        Dim Hyplink As New HyperLink
                        Dim hypLinkString As String = String.Empty
                        Dim HypImagePath As String = String.Empty

                        urlName = item("PortalName") 'dataset column for site name
                        hypLinkString = item("PortalURL") 'hyperlink
                        HypImagePath = item("imageFilePath").ToString()

                        cnt += 1
                        If (cnt > 0) Then

                        For cellCtr = 1 To cellCnt

                            Dim tCell As New TableCell()

                            Hyplink.Text = urlName 'get url name
                            Hyplink.NavigateUrl = hypLinkString 'add url to the name
                            If Not String.IsNullOrEmpty(HypImagePath) Then
                                Hyplink.ImageUrl = HypImagePath
                                Hyplink.ImageHeight = 50
                                Hyplink.ImageWidth = 50
                                Hyplink.Text = urlName
                            End If
                            'tCell.Text = "Row " & rowCtr & ", Cell " & cellCtr
                            ' Hyplink.ImageUrl = HypImagePath
                            Hyplink.CssClass = "urlImages"
                            Hyplink.Target = "_blank"
                            tCell.Controls.Add(Hyplink) 'assign contol to the cell
                            tRow.Cells.Add(tCell) ' add the cell
                           
                        Next
                        linkTable.Rows.Add(tRow)

                    End If

                Next

               
            Next




been looking at this to long hopefully fresh eyes can spot the issue

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: issue adding items to grid view by column

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14854
  • View blog
  • Posts: 59,272
  • Joined: 12-June 08

Re: issue adding items to grid view by column

Posted 22 February 2019 - 08:29 AM

Quote

what it is doing is creating all the cells in each row instead of 1 data point per cell per column row

Curious - why are you, at least from what I am understanding, fighting up against the prescribed path of a grid?

Side note, and it's because I am a curious cat and this always failed in my view - why is your grid dynamic? On a classic ASP.NET page it is infinitely easier to describe your grid and all the parts and just fill it versus needlessly going dynamic.
Was This Post Helpful? 0
  • +
  • -

#3 DarenR   User is offline

  • D.I.C Lover

Reputation: 598
  • View blog
  • Posts: 3,884
  • Joined: 12-January 10

Re: issue adding items to grid view by column

Posted 22 February 2019 - 11:17 AM

the grid is dynamic because they want the ability to add or remove programs at will and they requested only 4 columns per row. -- i think in the long run they want it to be android friendly like how an android screen looks with the icons.

i did figure this out after a lot of trial and error:

 Dim cellCnt As Integer = 0
            Dim tRow As New TableRow()

            For Each item As DataRow In dsDataSet.Tables(0).Rows
                Dim urlName As String = String.Empty
                Dim cnt As Integer = 0
                Dim Hyplink As New HyperLink
                Dim hypLinkString As String = String.Empty
                Dim HypImagePath As String = String.Empty

                urlName = item("PortalName") 'dataset column for site name
                hypLinkString = item("PortalURL") 'hyperlink
                HypImagePath = item("imageFilePath").ToString()

                cnt += 1
                If (cnt > 0) Then

                    Dim tCell As New TableCell()

                    Hyplink.Text = urlName 'get url name
                    Hyplink.NavigateUrl = hypLinkString 'add url to the name
                    If Not String.IsNullOrEmpty(HypImagePath) Then
                        Hyplink.ImageUrl = HypImagePath
                        Hyplink.ImageHeight = 75
                        Hyplink.ImageWidth = 125
                        Hyplink.Text = urlName
                    End If

                    ' Hyplink.CssClass = "urlImages"
                    Hyplink.Target = "_blank"
                    tCell.Controls.Add(Hyplink)
                    linkTable.CellPadding = 8
                    tCell.Width = 100

                    'assign contol to the cell
                    tRow.Cells.Add(tCell) ' add the cell
                    '  linkTable.Rows.Add(tRow) 'add the row to the table

                    cellCnt += 1
                    ' Next
                    If cellCnt = 4 Then
                        linkTable.Rows.Add(tRow)

                        cellCnt = 0
                        tRow = New TableRow()

                    End If

                End If

            Next
            linkTable.Rows.Add(tRow)

Attached image(s)

  • Attached Image

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1