Radgrid with nested view from generic class

4 posts, 0 answers
  1. CS
    CS avatar
    4 posts
    Member since:
    Oct 2015

    Posted 12 Apr Link to this post

    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

  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 15 Apr Link to this post

    Hello,

    If I correctly understand you requirement you need to pass the data from the xml file to the NestedView table. I would suggest you to instead using the generic class, simply to directly pass the DataSource to the Grid using its NeedDataSource and DetailTableDataBind event.
    I hope this helps.

    Regards,
    Maria Ilieva
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. CS
    CS avatar
    4 posts
    Member since:
    Oct 2015

    Posted 15 Apr Link to this post

    Thanks for Maria Ilieva for quick reply.

    I am using this method in the initial phase and its working fine, but we have a requirement to reload it again after the save function. Moreover I have written some additional functionality in DetailTableDataBind on the initial phase.

    I am working on a conversion project (Infragistics to Telerik Control) which is using generic class.

  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 20 Apr Link to this post

    Hi,

    If you change the xml file and simply call RadGrid1.Rebind() on the save button server click event this should update the records int he grid control.

    Regards,
    Maria Ilieva
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top