0

I have a website which is code generating practically everything on the page. The home page consists of a right menu which is being built via code. It uses System.Web.UI.WebControls.TableCell class and creates a td for every new item.

Here is a snippet of the code:

Public Sub BuildMainMenuStructure(ByVal Cell As TableCell, _
                                    ByVal Contents As DataTable, _
                                    ByVal ReadMode As Boolean, _
                                    ByVal CurrentPage As String, _
                                    ByVal RecSecurity As ApplicationRoleSecurity, _
                                    ByVal SourcePageRef As Integer, _
                                    ByVal IncludeMyIntranetPanel As Boolean)

    '-----------------------------------------------------------------
    'Div1 Contents
    '-----------------------------------------------------------------
    'Set up the contents in a div (panel) called pnlMainMenu1
    Dim mmContents As New MainMenuContents
    mmContents.ID = "pcaMainMenuContents"
    mmContents.SetControl(Contents, _
                          ReadMode, _
                          CurrentPage, _
                          RecSecurity, _
                          SourcePageRef)

    mintContentsCount = mmContents.Count

    Dim pnlMainMenu1 As New Panel
    With pnlMainMenu1
        .ID = "pcaMainMenuContentsPanel"
        'By default, this panel is visible:
        .Style.Add("visibility", "visible")
        .Controls.Add(mmContents)
    End With

In another area in the code a different section of the homepage is generated:

   If IncludeMyIntranetPanel And ReadMode Then

        'Set up the contents in a div (panel) called pnlMainMenu2
        Dim mmMyIntranet As New MainMenuMyIntranet
        mmMyIntranet.ID = "pcaMainMenuMyIntranet"
        mmMyIntranet.SetControl(Contents, _
                              ReadMode, _
                              CurrentPage, _
                              RecSecurity, _
                              SourcePageRef)

        Dim pnlMainMenu2 As New Panel
        With pnlMainMenu2
            .ID = "pcaMainMenuMyIntranetPanel"
            'By default, this panel is visible:
            .Style.Add("visibility", "visible")
            .Controls.Add(mmMyIntranet)
        End With

        'Add it to the cell:
        Cell.Controls.Add(pnlMainMenu2)

    End If 'End If IncludeMyIntranetPanel

Its adding the content via Cell.Controls.Add(pnlMainMenu2)

I am tasked with trying to re-skin the home page. Ideally I want to generate DIV classes so I can easily position the content.

Is there a .net class that I can use that grabs data from the database and creates div classes?

SOLDIER-OF-FORTUNE
  • 1,634
  • 5
  • 39
  • 66

1 Answers1

2

There are alternatives, certainly, but deciding which one to use depends a lot on exactly what you're trying to accomplish, and what version of .NET you're using.

The Panel control does, in fact, output divs to the page, though if your only requirement is "I want to output divs", I don't know that I'd recommend it - I stick with Panels for when I need to control, using ASP.NET, things like visibility for the controls it contains. However, for an existing site, it probably is the closest "drop in" replacement for the TableCell control.

The Literal control exists in most versions of .NET, and lets you have full control over what gets output to the screen, but, like the Panel control, it's not a data-bound control; you'd need to get your information in the codebehind, use it to add whatever you like to the .Text of your literal. The downside of this is that dumping exactly the HTML we want to the page from codebehind kind of goes against the ASP.NET way.

The ListView control is actually a databound control - you give it a database connection of some type, and it will loop over the results and display a list. You have reasonably full control over the HTML that's output in that list, so you could use divs, lis, etc, but it will be trickier (though nowhere near impossible) to use logic in determining what to display. (There is an earlier, related control, the Repeater, that's more kludgy to use, but exists in earlier versions of .NET)

Sheldon Griffin
  • 4,405
  • 1
  • 14
  • 5
  • 1
    I was getting a bit wordy there, but I feel I should reiterate: neither than Panel control nor the Literal control have any form of database interaction built in; you'd need to do your database stuff and add the output via codebehind. Also, the Panel control doesn't actually take text, unlike the TableCell - yes, it outputs DIVs, but you'd need to add a Label or HyperLink etc. control to actually output your text. – Sheldon Griffin Mar 02 '12 at 16:27
  • see the problem with the site I'm working with is everything is database / code generated. I dont think the developer knew what stylesheets actually where! There is talk of "re-skinning" the home page but alot of "stuff" goes on so its not a case of skinning the home page with a new design. – SOLDIER-OF-FORTUNE Mar 02 '12 at 16:36