I have manually created RadGrids based on data. The grids create just fine but I don't know how to add the sorting and pagination to a DYNAMICALLY created RadGrid.
Here is my RadGrid creation code:
Private Function CreateGrid(ByVal strLine As String) As RadGrid
Dim rg As New RadGrid
rg.ID = strLine rg.Width = Unit.Percentage(280) rg.PageSize = 40 rg.AllowPaging = True rg.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric rg.PagerStyle.AlwaysVisible = True rg.MasterTableView.PagerStyle.AlwaysVisible = True rg.AutoGenerateColumns = False rg.ExportSettings.FileName = strLine Dim boundColumn As GridBoundColumn boundColumn = New GridBoundColumn rg.MasterTableView.Columns.Add(boundColumn) boundColumn.DataField = "Process" boundColumn.HeaderText = "Process" boundColumn.UniqueName = "Process" boundColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center boundColumn = New GridBoundColumn rg.MasterTableView.Columns.Add(boundColumn) boundColumn.DataField = "Product" boundColumn.HeaderText = "Product" boundColumn.UniqueName = "Product" boundColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center boundColumn = New GridBoundColumn rg.MasterTableView.Columns.Add(boundColumn) boundColumn.DataField = "Tested" boundColumn.HeaderText = "Tested" boundColumn.UniqueName = "Tested" boundColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Right boundColumn = New GridBoundColumn rg.MasterTableView.Columns.Add(boundColumn) boundColumn.DataField = "Passed" boundColumn.HeaderText = "Passed" boundColumn.UniqueName = "Passed" boundColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Right boundColumn = New GridBoundColumn rg.MasterTableView.Columns.Add(boundColumn) boundColumn.DataField = "Failed" boundColumn.HeaderText = "Failed" boundColumn.UniqueName = "Failed" boundColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Right boundColumn = New GridBoundColumn rg.MasterTableView.Columns.Add(boundColumn) boundColumn.DataField = "Yield" boundColumn.HeaderText = "Yield" boundColumn.UniqueName = "Yield" boundColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Right boundColumn = New GridBoundColumn rg.MasterTableView.Columns.Add(boundColumn) boundColumn.DataField = "Top5" boundColumn.HeaderText = "Top 5 Rejects" boundColumn.UniqueName = "Top5" boundColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Left boundColumn = New GridBoundColumn rg.MasterTableView.Columns.Add(boundColumn) boundColumn.DataField = "TrueFailure" boundColumn.HeaderText = "True Failure?" boundColumn.UniqueName = "TrueFailure" boundColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center Return rg
End Function
The way I have done it on a project that was NOT dynamically created:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Session("Report") = CreateTable()
End If
End Sub
Protected Sub rdgAgeReport_PageIndexChanged(sender As Object, e As Telerik.Web.UI.GridPageChangedEventArgs) Handles rdgAgeReport.PageIndexChanged
rdgAgeReport.DataSource = CType(Session("Report"), DataTable)
rdgAgeReport.DataBind()
End Sub Protected Sub rdgAgeReport_PageSizeChanged(sender As Object, e As Telerik.Web.UI.GridPageSizeChangedEventArgs) Handles rdgAgeReport.PageSizeChanged
rdgAgeReport.DataSource = CType(Session("Report"), DataTable)
rdgAgeReport.DataBind()
End Sub