Bind additional records to RadGrid

4 posts, 1 answers
  1. Kurt Kluth
    Kurt Kluth avatar
    167 posts
    Member since:
    Oct 2009

    Posted 23 May 2018 Link to this post

    I have a RadGrid where the data is from our SQL Database using a NeedDataSource and works just fine.  What I would like to do is append 5 additional records that are not found in our database and will remain static. How can I add these additional records to the grid?

     

     

  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5529 posts

    Posted 28 May 2018 Link to this post

    Hello Kurt,

    Since you are using the NeedDataSource event, you must have some object that stores the data taken from the SQL server that you then pass to the grid. This is the object you need to append those records to before giving it to the grid.


    Regards,
    Marin Bratanov
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Kurt Kluth
    Kurt Kluth avatar
    167 posts
    Member since:
    Oct 2009

    Posted 29 May 2018 in reply to Marin Bratanov Link to this post

    Here is what I was attempting to do by adding additional records to the Datatable before it populates the grid.  Receiving an error when doing this.  

     

    Private Function ReadRecords() As DataTable
           oConn.Open()
           Dim ocmd As New SqlCommand("sp_getASIUser_Reports", oConn)
           ocmd.CommandType = CommandType.StoredProcedure
     
           With ocmd.Parameters
               .Add(New SqlParameter("@ReportID", 5))
               .Add(New SqlParameter("@Selection", DBNull.Value))
               .Add(New SqlParameter("@bShowCell", 1))
           End With
           reader = ocmd.ExecuteReader()
           Dim dt As New DataTable
           dt.Load(reader)
           oConn.Close()
     
     
           Dim workRow As DataRow
           workRow = dt.NewRow()
     
           workRow("FullName") = "Auditorium"
           workRow("Extension") = "144"
           workRow("WorkCellPhone") = ""
           workRow("DirectDial") = ""
           'workRow("DirectFax") = ""
           workRow("HomePhoneNum") = ""
           'workRow("iUser_ID") = ""
           dt.Rows.Add(workRow)
     
           workRow(0) = "Board Room"
           workRow(1) = "131"
           'workRow("WorkCellPhone") = ""
           'workRow("DirectDial") = ""
           'workRow("DirectFax") = ""
           'workRow("HomePhoneNum") = ""
           'workRow("iUser_ID") = ""
           dt.Rows.Add(workRow)
     
           Return dt
       End Function
  4. Answer
    Marin Bratanov
    Admin
    Marin Bratanov avatar
    5529 posts

    Posted 30 May 2018 Link to this post

    Hi Kurt,

    The following seems to work fine for me and I can only suggest that you debug the problem and compare with my example. Alternatively, you can consider a strongly typed collection like a List<someObject> that is easy to append to.

    <telerik:RadGrid runat="server" ID="rg1"></telerik:RadGrid>
    Protected Sub rg1_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs) Handles rg1.NeedDataSource
        Dim dt As DataTable = GetData()
        dt.Rows.Add(New Object() {"fourth", "fourthRecord2", 4, "four"})
        dt.Rows.Add(New Object() {"fifth", "fifthRecord2", 5, "five"})
        DirectCast(sender, RadGrid).DataSource = dt
    End Sub
     
    Protected Function GetData() As DataTable
        Dim tbl As New DataTable()
        tbl.Columns.Add(New DataColumn("someField"))
        tbl.Columns.Add(New DataColumn("OtherField"))
        tbl.Columns.Add(New DataColumn("answer"))
        tbl.Columns.Add(New DataColumn("FourthColumn"))
        tbl.Rows.Add(New Object() {"first", "firstRecord2", 1, "one"})
        tbl.Rows.Add(New Object() {"second", "secondRecord2", 2, "two"})
        tbl.Rows.Add(New Object() {"third", "thirdRecord2", 3, "three"})
        Return tbl
    End Function


    Regards,
    Marin Bratanov
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top