I am using rad grid to load the data in a nested view and save it into the database using a generic class (get/set the data's based on the controls in the form).
After saving the data I need to reload the data back into the radgrid in the nested view (using OnDetailTableDataBind with HierarchyLoadMode=ServerBind).
I have all the required data in the form of an xml
<
Rows
>
<
Row
> Parent View
<
SubRow
>
Child View
</
SubRow
>
</
Row
>
</
Rows
>
Can any one please help how to set OnDetailTableDataBind event from a generic class?
Private Function SetGridControls(ByVal telerikGrid As RadGrid, ByVal gridValue As String) As RadGrid
Dim loXML As XmlDocument = New XmlDocument
Dim dtRowTable As DataTable
Dim dtColumnTable As DataTable
telerikGrid.AutoGenerateColumns = True
If gridValue.Length > 0 Then
loXML.LoadXml(gridValue)
Dim elementChild As XmlNodeList = loXML.GetElementsByTagName("SubRow")
Dim loElem As XmlElement
Dim loAtt As XmlAttribute
dtRowTable = New DataTable 'Contains all the ROWS
dtColumnTable = New DataTable 'Contains all the SUBROWS
Dim blnRowDT As Boolean = False
Dim blnColumnDT As Boolean = False
dtRowTable = New DataTable()
dtColumnTable = New DataTable()
'Loading all the subrows
Dim SubRowList As XmlNodeList = loXML.GetElementsByTagName("SubRow")
For Each node As XmlNode In SubRowList
If blnColumnDT = True Then
Exit For
End If
For i As Integer = 0 To node.Attributes.Count - 1
dtColumnTable.Columns.Add(New DataColumn(node.Attributes(i).Name))
Next
blnColumnDT = True
Next
For Each node As XmlNode In SubRowList
Dim row As DataRow = dtColumnTable.NewRow()
For i As Integer = 0 To node.Attributes.Count - 1
Dim columnName As String = node.Attributes(i).Name
Try
Thread.CurrentThread.CurrentCulture = USCulture
If Not IsNumeric(node.Attributes(i).gridValue) AndAlso IsDate(node.Attributes(i).gridValue) Then
row(columnName) = DateString(CDate(node.Attributes(i).gridValue), StringFormat.ShortDate)
Else
row(columnName) = node.Attributes(i).gridValue
End If
Catch e As SystemException
row(columnName) = node.Attributes(i).gridValue
Finally
Thread.CurrentThread.CurrentCulture = CultureInfo
End Try
Next
dtColumnTable.Rows.Add(row)
Next
'Loading all the rows
For Each loElem In loXML.DocumentElement
If (blnRowDT = True) Then
Exit For
End If
For Each loAtt In loElem.Attributes
If Not dtRowTable.Columns.Contains(loAtt.Name) Then
dtRowTable.Columns.Add(New DataColumn(loAtt.Name))
End If
Next
blnRowDT = True
Next
Dim iRow As Integer = 1
For Each loElem In loXML.DocumentElement
Dim row As DataRow = dtRowTable.NewRow()
For Each loAtt In loElem.Attributes
Dim columnName As String = loAtt.Name
Try
Thread.CurrentThread.CurrentCulture = USCulture
If Not IsNumeric(loAtt.gridValue) AndAlso IsDate(loAtt.gridValue) Then
row(columnName) = DateString(CDate(loAtt.gridValue), StringFormat.ShortDate)
Else
If loAtt.gridValue.Trim = "" And TypeOf (row(columnName)) Is Double Then
row(columnName) = 0
Else
row(columnName) = loAtt.gridValue
End If
End If
Catch e As SystemException
row(columnName) = loAtt.gridValue
Finally
Thread.CurrentThread.CurrentCulture = CultureInfo
End Try
Next
dtRowTable.Rows.Add(row)
iRow += 1
Next
'Attaching all the rows into datasource
telerikGrid.DataSource = dtRowTable
End If
Return telerikGrid
End Function