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

Multi Column Sorting on a dynamically built grid

1 Answer 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 10 Oct 2012, 12:24 PM
I am dynamically building a grid control on the PAGE_LOAD event. Column headers and data are all bound on the fly, nothing is static. I am using the the Filter Icons and have set AllowMultiColumnSorting = "TRUE".

I am able to sort only by one column. When I try to enter data into a second field to sort by a second field, my first sort value goes away. What is needed to keep these sort values?

Here is some code to help you understand how my grid is built.

All help is greatly appreciated!

Dim RadGrid1 As RadGrid = New RadGrid
 
RadGrid1.ID = "RadGrid1"
RadGrid1.Width = Unit.Percentage(100)
RadGrid1.PageSize = 5
RadGrid1.AllowPaging = True
RadGrid1.AllowSorting = True
RadGrid1.AllowFilteringByColumn = True
RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric
RadGrid1.PagerStyle.Position = GridPagerPosition.TopAndBottom
RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.TopAndBottom
RadGrid1.MasterTableView.CommandItemStyle.BackColor = Color.LightGray
RadGrid1.MasterTableView.CommandItemStyle.ForeColor = Color.Black
RadGrid1.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = False
RadGrid1.MasterTableView.CommandItemSettings.ShowExportToPdfButton = True
RadGrid1.MasterTableView.CommandItemSettings.ShowExportToExcelButton = True
RadGrid1.MasterTableView.AllowFilteringByColumn = True
RadGrid1.ExportSettings.ExportOnlyData = True
RadGrid1.AutoGenerateColumns = False
RadGrid1.Skin = "MetroTouch"
RadGrid1.BorderStyle = BorderStyle.None
RadGrid1.MasterTableView.HeaderStyle.ForeColor = Color.White
RadGrid1.MasterTableView.EnableColumnsViewState = False
RadGrid1.MasterTableView.PageSize = 15
RadGrid1.MasterTableView.EditMode = GridEditMode.InPlace
RadGrid1.MasterTableView.AllowMultiColumnSorting = True

Dim tblStopData As DataTable = New DataTable
 
            Dim cmd As SqlCommand = New SqlCommand("SP_STORED_PROC", conn)
 
            cmd.CommandType = CommandType.StoredProcedure
 
            Dim adapter As New SqlDataAdapter(cmd)
            adapter.SelectCommand.CommandTimeout = 300
 
            adapter.Fill(tblStopData)
 
            Dim name(tblStopData.Columns.Count) As String
            Dim i As Integer = 0
            For Each column As DataColumn In tblStopData.Columns
                Dim boundColumn As GridBoundColumn = New GridBoundColumn
                RadGrid1.MasterTableView.Columns.Add(boundColumn)
                boundColumn.DataField = column.ColumnName
                boundColumn.HeaderText = column.ColumnName
                'boundColumn.AndCurrentFilterFunction = GridKnownFunction.Contains
                boundColumn.ShowFilterIcon = True
            Next
 
            RadGrid1.DataSource = tblStopData
            RadGrid1.Rebind()

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 12 Oct 2012, 12:20 PM
Hello Josh,

Thank you for contacting us.

Could you please share in which event and why are you using Rebind() after defining the DataSource?
Please note that performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Paging, Sorting, Filtering require accommodating appropriate database operations. To use them with Simple Databinding you will need to declare custom event handling for every operation which requires binding to your DataSource. Therefore, we strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Advanced Data Binding

Furthermore, please verify that you are closely following the steps provided in the following topic when creating RadGrid programmatically:
 ( Section Creating the grid entirely in the code behind )
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html#Section4

It would be great if you could send us a sample runnable application demonstrating the problematic behavior or provide us the exact steps to replicate the issue. Thus we will be able to further analyze the project and provide a proper solution.

Please do not hesitate to share any detail which could be related to the issue. Looking forward to your reply.

All the best,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Josh
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or