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

[Solved] Grid Sorting Collection is Null for second time.

1 Answer 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 14 Dec 2009, 10:11 AM


Hi,

I have default sorting in my data grid. So I setup default GridSortExpression in Page Load.
When I retrieve the data, I pass the Field Name and Sort Order to my SQL Query. So GetSortExpression () function return Sort Expression object.
It is working fine for first time and show background color and sort indicator but if u clicks this default sort column again I got the following error. Yes, there is o count in tableView.SortExpressions collection. But I click other column first then click that date column, grid sorted accordingly.

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: indexe


<telerik:GridTemplateColumn DataField="ProcessDate" HeaderText="Process Date" UniqueName="ProcessDate" Display="true" SortExpression="ProcessDate"
<ItemTemplate>                                          
<asp:Label ID="ProcessDate_TimeZone" runat="server"></asp:Label>                                      
</ItemTemplate>                                      
</telerik:GridTemplateColumn> 

 

protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!this.IsPostBack) 
            { 
                rgProcessLog.MasterTableView.SortExpressions.Clear(); 
                GridSortExpression expression = new GridSortExpression(); 
                expression.FieldName = "ProcessDate"
                expression.SortOrder = GridSortOrder.Descending; 
                rgProcessLog.MasterTableView.SortExpressions.Add(expression); 
            } 
        } 

protected SortExpression GetSortExpression() 
        { 
            GridTableView tableView = rgProcessLog.MasterTableView; 
            SortExpression expression = new SortExpression(); 
            expression.FileName = tableView.SortExpressions[0].FieldName; 
            expression.SortOrder = (DCCPP.BusinessEntities.Enums.Sorting)Enum.Parse(typeof(DCCPP.BusinessEntities.Enums.Sorting), tableView.SortExpressions[0].SortOrder.ToString()); 
            return expression; 
 
        } 

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 17 Dec 2009, 08:47 AM
Hi Alex,

 I reviewed the code, and the setup looks correct. However, to properly track the issue, it will be best if you open a formal support ticket, and send us a small working project, demonstrating your setup, and showing the unwanted behavior. We will debug it locally, and get back to you with additional information.


Best wishes,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or