This is a migrated thread and some comments may be shown as answers.

Bind additional records to RadGrid

3 Answers 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kurt Kluth
Top achievements
Rank 1
Kurt Kluth asked on 23 May 2018, 07:53 PM

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?

 

 

3 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 28 May 2018, 08:49 AM
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.
0
Kurt Kluth
Top achievements
Rank 1
answered on 29 May 2018, 12:53 PM

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
0
Accepted
Marin Bratanov
Telerik team
answered on 30 May 2018, 09:36 AM
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.
Tags
Grid
Asked by
Kurt Kluth
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Kurt Kluth
Top achievements
Rank 1
Share this question
or