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
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
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 FunctionThe 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 = dtEnd SubProtected 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 tblEnd FunctionRegards,
Marin Bratanov
Progress Telerik