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?
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)