One clarification.
I have not loaded the actual dataset, yet. I am loading the view structure
to determine the layout and controls needed. The Databind will function will
call the class which will actually load the data onto the web form.
Code snip of the panel builder (not complete, and in early development):
Caller would on page_Int would be: Builder.CreateFormPanel(me, 'vw_abc')
***START HERE
Public Function CreateFormPanel(ByVal objPage As Page, ByVal
LayoutBasedOn As String) As Boolean
Dim MySize As New dbTable
ParentPage = objPage
With MySize
.ViewtoLoad = "[aspnet_!PanelLayout]"
.FiltertoView = LayoutBasedOn
If .OpenResults Then
Dim MyTable As Table = CreateTable()
Do Until .EOF
Dim pstrCaption As String =
ParseString(.mData.GetProperty("ID")) & ":"
Dim pstrTag As String = .mData.GetProperty("ID")
Dim pstrType As String =
..mData.GetProperty("DataType")
Dim pintLength As Integer =
..mData.GetProperty("Length")
Dim pintScale As Integer =
..mData.GetProperty("Scale")
Dim pintAllowNulls As Integer =
..mData.GetProperty("AllowNulls")
If pstrTag.ToUpper = "DELETED" Then pstrType =
"bit"
If pstrCaption.StartsWith("_header") Then
MyTable.Rows.Add(CreateHeaderRow(pstrTag,
pstrCaption))
Else
MyTable.Rows.Add(CreateDataRow(pstrTag,
pstrCaption, pstrType, pintLength, pintScale, pintAllowNulls))
End If
.MoveNext()
Loop
MyTable.Rows.Add(CreateValidationRow)
MyTable.Rows.Add(CreateButtonRow("Form"))
_newpanel = CreatePanel()
_newpanel.Controls.Add(MyTable)
.CloseRecordSet()
End If
End With
Return True
End Function
Private Function CreatePanel(Optional ByVal NoFill As Boolean =
False) As Panel
Dim oPanel As Panel = New Panel
'Default Panel Properties
With oPanel
.Style("position") = "relative"
.BorderColor = System.Drawing.SystemColors.ActiveBorder
.BorderStyle = BorderStyle.Ridge
.BorderWidth = Unit.Pixel(1)
If Not NoFill Then
.Width = Unit.Percentage(100)
.Height = Unit.Percentage(100)
.ScrollBars = ScrollBars.Vertical
Else
.Width = Unit.Pixel(10)
.Height = Unit.Pixel(10)
.ScrollBars = ScrollBars.None
End If
End With
Return oPanel
End Function
Private Function CreateTable() As Table
Dim tbNew As Table = New Table
With tbNew
.ID = "tableData"
.Rows.Clear()
.BorderWidth = 0
.BorderColor = Drawing.Color.Black
.CellPadding = 1
.CellSpacing = 0
.Height = Unit.Percentage(100)
.Width = Unit.Percentage(100)
.Style("Postion") = "table-layout:fixed"
End With
Return tbNew
End Function
Private Function CreateHeaderRow(ByVal TagID As String, ByVal
CaptionID As String) As TableRow
Dim tbRow As TableRow = New TableRow
tbRow.ID = "th" & TagID
tbRow.Height = 10
Dim tbLabelCell As New TableCell
tbLabelCell.ID = "td" & TagID
tbLabelCell.ColumnSpan = 2
tbLabelCell.BackColor = Drawing.Color.RoyalBlue
tbLabelCell.ForeColor = Drawing.Color.White
tbLabelCell.Font.Bold = True
tbLabelCell.Font.Size = FontUnit.Medium
tbLabelCell.Controls.Add(CreateLabel(CaptionID, TagID, True))
tbRow.Cells.Add(tbLabelCell)
If (TagID = "_header0" Or TagID = "_header99") Then
isReadOnly = True
Else
isReadOnly = False
End If
Return tbRow
End Function
Private Function CreateDataRow(ByVal TagID As String, ByVal
CaptionID As String, ByVal DataType As String, _
Optional ByVal FieldLength As Integer = 10,
Optional ByVal FieldScale As Integer = 0, _
Optional ByVal AllowNulls As Integer = 0) As
TableRow
Dim CheckIt As clsComboLoader = Nothing
Dim tbRow As TableRow = New TableRow
Dim pintColumns As Integer = FieldLength
Dim pintRows As Integer = 1
tbRow.ID = "tr" & TagID
tbRow.Height = 10
pintColumns *= 10
If pintColumns > MaxWidth Then
pintRows = pintColumns / MaxWidth
If pintRows > MaxRows Then pintRows = MaxRows
pintColumns = MaxWidth
ElseIf pintColumns < MinWidth Then
pintColumns = MinWidth
End If
Dim tbLabelCell As New TableCell
tbLabelCell.ID = "tdlbl" & TagID
tbLabelCell.Width = Unit.Percentage(25)
tbLabelCell.Controls.Add(CreateLabel(CaptionID, TagID))
tbRow.Cells.Add(tbLabelCell)
Dim tbTextCell As New TableCell
tbTextCell.ID = "td" & TagID
tbTextCell.Width = Unit.Percentage(75)
Select Case DataType.ToUpper
Case "DATETIME"
If TagID.ToUpper = "LASTMODIFIED" Then
tbTextCell.Controls.Add(CreateDateTimeBox(TagID))
ElseIf TagID.ToUpper.Contains("TIME") Then
tbTextCell.Controls.Add(CreateTimeBox(TagID))
Else
tbTextCell.Controls.Add(CreateDateBox(TagID))
End If
Case "INT", "SMALLINT", "TINYINT", "BIGINT"
tbTextCell.Controls.Add(CreateIntegerBox(TagID,
FieldLength))
Case "MONEY"
tbTextCell.Controls.Add(CreateCurrencyBox(TagID))
Case "NUMERIC"
tbTextCell.Controls.Add(CreateNumberBox(TagID,
FieldLength, FieldScale))
Case "BIT"
tbTextCell.Controls.Add(CreateCheckBox(TagID))
Case "CHAR", "VARCHAR", "NVARCHAR"
If Not isReadOnly Then
CheckIt = New clsComboLoader
If CheckIt.LoadDropDown(TagID, FieldLength) Then
tbTextCell.Controls.Add(CreateComboBox(TagID,
FieldLength))
Else
tbTextCell.Controls.Add(CreateTextBox(TagID,
FieldLength, pintColumns, pintRows))
End If
CheckIt = Nothing
Else
tbTextCell.Controls.Add(CreateTextBox(TagID,
FieldLength, pintColumns, pintRows))
End If
Case "TEXT"
tbTextCell.Controls.Add(CreateTextBox(TagID,
FieldLength, pintColumns, pintRows))
Case Else
WriteInformation(DataType.ToUpper, 522)
End Select
If AllowNulls <> 0 Then
tbTextCell.Controls.Add(BuildFieldValidator(strPrefix &
TagID))
End If
tbRow.Cells.Add(tbTextCell)
Return tbRow
End Function
Private Function CreateTextBox(ByVal TagID As String, ByVal
ValueLength As Integer, Optional ByVal BoxWidth As Integer = 40, Optional
ByVal BoxHeight As Integer = 1) As WebInput
Dim txtInput As WebInput = New ISNet.WebUI.WebControls.WebInput
Dim pstrFormat As String = ">&<"
For I As Integer = 2 To ValueLength
pstrFormat += "C"
Next I
strPrefix = "txt"
txtInput.ID = strPrefix & TagID
txtInput.AcceptEnter = False
txtInput.CaseSentitive = True
txtInput.Height = BoxHeight * 20
txtInput.HighLight.Type = HighLightType.Character
txtInput.MaxLength = ValueLength
txtInput.ReadOnly = isReadOnly
txtInput.Rows = BoxHeight
If BoxHeight = 1 Then
txtInput.TextMode = WebControls.TextBoxMode.SingleLine
Else
txtInput.TextMode = WebControls.TextBoxMode.MultiLine
End If
txtInput.Width = BoxWidth
txtInput.Attributes.Add("Tag", TagID)
'Dim MyTag2Be As String = "<%# Dataform.Record(""" & TagID &
""")%>"
'txtInput.Text = MyTag2Be.ToString
Return txtInput
End Function
*** END HERE
Cowboy (Gregory A. Beamer) said:
Instead of using simple binding, bind to the column, by index, in the
background.
TextBox1.Text = DataSet.Rows[0][0]; //second 0 = column
This gives you the ability to create the form, on the fly, and fill the
textboxes as needed. And, if you pull the name of the column, you can even
label it.
Or, you can create your own composite control, with a label and textbox and
feed the two values as you add it. Then, you can easily spin through a for
loop and add everything in the dataset, with proper column names.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
********************************************
Think outside the box!
********************************************
Jeremy Bruening said:
I have found numerous iterations of server classes creating controls and
adding them to web pages. However, I have never found any uses with the
databind. I would like to set the text of the object to a databind call,
not
just a string value.
Textbox1.Text = <%# DataBind.Eval("Col001")%>
The key to my design is; the class determines the controls needed from the
SQL view that is presented to the page. This would allow me to custom
design
the view to 2,3,4, 10,20 columns/controls, but use only one page for data
presentation. And allow the user to page thru the results without having
to
rebuild the page.