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

Item command default sort functionality passthrough

4 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott Hannon
Top achievements
Rank 1
Scott Hannon asked on 12 Mar 2012, 08:06 PM
Please excuse if this is a duplicate, but did not find anything using search.

I have a grid using Grid_ItemCommand like so. If I want the built-in sorting functionality to continue to work, what do I put in the "case sort" :
Protected Sub rgOrderStats_ItemCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles rgOrderStats.ItemCommand
       Select Case e.CommandName
           Case "RowClick" 'show detail grid
               Dim index As Integer = e.Item.ItemIndex
               Dim item As GridDataItem = rgOrderStats.Items(index)
               'Get the values from the row using the columnUniqueName    
               Dim id As String = item("HID").Text
               Session("hid") = id
               'call detail
               'show radwindow with grid
               ScriptManager.RegisterStartupScript(Me.Page, Page.GetType(), "popgrid", "openDetail();", True)
           Case ("RebindGrid") 'refresh
               rgOrderStats.Rebind()
           Case "ExportToPdf"
               rgOrderStats.MasterTableView.ExportToPdf()
           Case "ExportToWord"
               rgOrderStats.MasterTableView.ExportToWord()
           Case "ExportToXLS"
               rgOrderStats.MasterTableView.ExportToExcel()
           Case "Sort"
               '??
       End Select
 
   End Sub

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Mar 2012, 05:09 AM
Hello,

If you want to sort the entire grid in the ItemCommand event.Try the following code.
VB:
rgOrderStats.AllowSorting = True

You can also set  SortExpression as shown below.
VB:
Dim sortExpr As New GridSortExpression()
sortExpr.FieldName = "FieldName"
sortExpr.SortOrder = GridSortOrder.Ascending
rgOrderStats.MasterTableView.SortExpressions.AddSortExpression(sortExpr)

-Shinu.
0
Scott Hannon
Top achievements
Rank 1
answered on 13 Mar 2012, 02:32 PM
Thanks, Shinu.
I tried the AllowSorting = True, but this did not actually make the grid use the default built-in sorting functionality. I do not want to manually manage the sorting. Currently, when I click a header to sort, the grid goes blank. Is there some method to pass sort control back to the grid itself?
0
Shinu
Top achievements
Rank 2
answered on 14 Mar 2012, 05:37 AM
Hello Scott,

I suppose this issue arises because you are using simple databinding to bind the grid. For implementing advanced features such as sorting, paging etc RadGrid must be bound using declarative data sources or through the NeedDataSource event. Check the following help documentation which explains more about this.
Advanced Data-binding (using NeedDataSource event).

-Shinu.
0
Scott Hannon
Top achievements
Rank 1
answered on 21 Mar 2012, 05:01 PM
I ended up using this in the Case "Sort":
Dim sortExpr As New GridSortExpression()
sortExpr.FieldName = DirectCast(e, GridSortCommandEventArgs).SortExpression '"FieldName"
sortExpr.SortOrder = DirectCast(e, GridSortCommandEventArgs).NewSortOrder 'GridSortOrder.Ascending
rgOrderStats.MasterTableView.SortExpressions.AddSortExpression(sortExpr)
Then did a ReBind().
Tags
Grid
Asked by
Scott Hannon
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Scott Hannon
Top achievements
Rank 1
Share this question
or