Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Public Function AutoBindToForm(ByVal _Me As Control, ByVal tbl As DataTable) As DataTable
Dim Rw As DataRow
If tbl.Rows.Count = 0 Then
Rw = tbl.NewRow
Else
Rw = tbl.Rows(0)
End If
Dim c As DataColumn
Dim ctl As Object
For Each c In tbl.Columns
ctl = FindMyControlDeep(_Me, "bnd_" & c.ColumnName)
If Not ctl Is Nothing Then
PopulateControl(ctl, Rw, c)
End If
Next
Return tbl
End Function
Public Function FindMyControlDeep(ByVal p As Object, ByVal MyId As String) As Object
Try
Dim ctl As Object
If p Is Nothing Then Return Nothing
If p.HasControls Then
Dim obj As Object
ctl = p.FindControl(MyId)
If Not ctl Is Nothing Then Return ctl
For Each obj In p.Controls
ctl = FindMyControlDeep(obj, MyId)
If Not ctl Is Nothing Then Return ctl
Next
End If
Catch
End Try
Return Nothing
End Function
Public Function PopulateControl(ByVal Ctl As Object, ByVal Rw As DataRow, ByVal c As DataColumn) As Boolean
If TypeOf Ctl Is TextBox Then
Ctl.Text = CStr(Null2z(Rw(c.ColumnName), ""))
Return True
ElseIf TypeOf Ctl Is Label Then
Ctl.Text = CStr(Null2z(Rw(c.ColumnName), ""))
Return True
ElseIf TypeOf Ctl Is RadioButton Then
SetGroupValue(Ctl.Parent, Ctl.GroupName, Null2z(Rw(c.ColumnName), ""))
Return True
ElseIf TypeOf Ctl Is CheckBox Then
Ctl.checked = CBool(Null2z(Rw(c.ColumnName), False))
Return True
ElseIf TypeOf Ctl Is System.Web.UI.HtmlControls.HtmlInputCheckBox Then
Ctl.checked = CBool(Null2z(Rw(c.ColumnName), False))
Return True
ElseIf TypeOf Ctl Is System.Web.UI.HtmlControls.HtmlInputFile Then
Ctl.value = CStr(Null2z(Rw(c.ColumnName), ""))
Return True
ElseIf TypeOf Ctl Is System.Web.UI.HtmlControls.HtmlInputHidden Then
Ctl.value = CStr(Null2z(Rw(c.ColumnName), ""))
Return True
ElseIf TypeOf Ctl Is DropDownList Then
Dim obj As DropDownList = CType(Ctl, DropDownList)
SelectListBoxValue(obj, CStr(Null2z(Rw(c.ColumnName), "")))
'obj.SelectedValue = CStr(Null2z(Rw(c.ColumnName), ""))
Return True
ElseIf TypeOf Ctl Is ListBox Then
Dim obj As ListBox = CType(Ctl, ListBox)
'obj.SelectedValue = CStr(Null2z(Rw(c.ColumnName), ""))
SelectListBoxValue(obj, CStr(Null2z(Rw(c.ColumnName), "")))
Return True
ElseIf Ctl.GetType.ToString = "Telerik.WebControls.RadEditor" Then
Ctl.Html = CStr(Null2z(Rw(c.ColumnName), ""))
Return True
ElseIf TypeOf Ctl Is System.Web.UI.HtmlControls.HtmlSelect Then
Dim obj As System.Web.UI.HtmlControls.HtmlSelect = CType(Ctl, System.Web.UI.HtmlControls.HtmlSelect)
SelectSelectOptionValue(obj, CStr(Null2z(Rw(c.ColumnName), "")))
'obj.SelectedValue = CStr(Null2z(Rw(c.ColumnName), ""))
Return True
ElseIf TypeOf Ctl Is Web.UI.UserControl Then
Dim ctl2 As Web.UI.UserControl = CType(Ctl, Web.UI.UserControl)
If ctl2.HasControls Then
Dim ctl3 As Object
For Each ctl3 In ctl2.Controls
If PopulateControl(ctl3, Rw, c) Then
Return True
End If
Next
End If
End If
End Function
Public Sub SelectListBoxValue(ByRef MylistBox As Object, ByVal MyVal As Object)
Dim obj As DropDownList = CType(MylistBox, DropDownList)
Dim v As String = CStr(MyVal)
If Not v = Nothing Then v = v.ToLower
Dim i As Integer
For i = 0 To obj.Items.Count - 1
If CType(obj.Items(i), ListItem).Value.ToLower = v Then
obj.SelectedIndex = i
Exit For
End If
Next
End Sub
Public Sub UpdateFromForm(ByVal _Me As Control, ByRef Tbl As DataTable)
Dim Rw As DataRow = Tbl.Rows(0)
UpdateFromForm(_Me, Rw)
End Sub
Public sub UpdateFromForm(ByVal _Me As Control, ByRef Rw As DataRow)
Dim c As DataColumn
Dim ctl As Control
Dim tbl As DataTable = Rw.Table
For Each c In tbl.Columns
ctl = FindMyControlDeep(_Me, "bnd_" & c.ColumnName)
If Not ctl Is Nothing Then
Dim Obj As Object
If TypeOf ctl Is TextBox Then
Obj = CastDBType(CType(ctl, TextBox).Text, c)
ElseIf TypeOf ctl Is Label Then
Obj = CastDBType(CType(ctl, Label).Text, c)
ElseIf TypeOf ctl Is RadioButton Then
Dim ctl2 As RadioButton = CType(ctl, RadioButton)
Obj = CastDBType(GetGroupValue(_Me, ctl2.GroupName), c)
ElseIf TypeOf ctl Is CheckBox Then
Obj = CastDBType(CType(ctl, CheckBox).Checked, c)
ElseIf TypeOf ctl Is DropDownList Then
Obj = CastDBType(GetListBoxValue(CType(ctl, DropDownList)), c)
ElseIf TypeOf ctl Is System.Web.UI.HtmlControls.HtmlSelect Then
Obj = CastDBType(GetListBoxValue(CType(ctl, System.Web.UI.HtmlControls.HtmlSelect)), c)
ElseIf TypeOf ctl Is System.Web.UI.HtmlControls.HtmlInputFile Then
Obj = CastDBType(GetFileName(CType(ctl, System.Web.UI.HtmlControls.HtmlInputFile).Value), c)
ElseIf TypeOf ctl Is System.Web.UI.HtmlControls.HtmlInputHidden Then
Obj = CastDBType(CType(ctl, System.Web.UI.HtmlControls.HtmlInputHidden).Value, c)
ElseIf TypeOf ctl Is ListBox Then
Obj = CastDBType(GetListBoxValue(CType(ctl, ListBox)), c)
ElseIf ctl.GetType.ToString = "Telerik.WebControls.RadEditor" Then
Obj = CastDBType(CType(ctl, Object).Html, c)
End If
Rw(c.ColumnName) = Obj
End If
Next
End Sub
Public Function CastDBType(ByVal s As Object, ByVal c As DataColumn, Optional ByVal DefaultVal As Object = Nothing) As Object
If DefaultVal = Nothing Then DefaultVal = DBNull.Value
If s = Nothing Then
Return DefaultVal
End If
If TypeOf s Is String Then
If s.length = 0 Then
Return DefaultVal
End If
End If
Dim t As System.Type = c.DataType
If t.Name = "Boolean" Then
If s = "1" Or s = 1 Then
s = True
End If
If s = "0" Or s = 0 Then
s = False
End If
End If
Return Convert.ChangeType(s, t)
End Function