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

autogeneratecolumn and filtering/sorting problem

3 Answers 43 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lasly
Top achievements
Rank 1
Lasly asked on 31 May 2012, 11:57 AM

Hi!

I've a radgrid with autogeneratecolumn=true, i'm using advenced databinding to bind the data.

when i change the page or apply filter/sorting the radgrid throws exception during the binding (eg column not found).

the problem occures when change the datasource and reloaded the page.

I tried to set enableviewstatecolumn=false but not works.

Can I help me?

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 05 Jun 2012, 12:17 PM
Hello Lasly,

I am afraid it is not possible to replicate the issue on our side just by the provided information so far. Please find the attached sample RadGrid Web Site implemented with Advanced DataBinding and let me know whether I am missing something out.

It would be best if you open a support ticket and send us a runnable sample application demonstrating the problematic behavior. Thus, we will be able to further analyze the project and provide a proper solution.

Greetings,
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.
0
Lasly
Top achievements
Rank 1
answered on 05 Jun 2012, 12:52 PM
Hi!

Thanks for the reply.

In your example the select clause is always the same, in my case I change select clause too.

For example the first select contains 3 columns (id, description, value), and the second select contains 2 column (id, description). 

1. using the first select ordering by "value column" clicking to the column.

2. change the datasource via button postback doing rebind

3. during rebind radgrid throws exception. (column value not found). 

I think the solution is clear the  filtering,ordering,sorting and grouping expression. Is the correct way? 

There is another  way to solve the problem?

0
Accepted
Eyup
Telerik team
answered on 07 Jun 2012, 03:46 PM
Hi Lasly,

You will not face this issue if you have sorted a given column with a datafield also contained in the new datasource. But since you are sorting the initial grid with a datafield which the new datasourse does not contain, this error arises as expected.

One possible approach would be to clear the sorting expressions as you have pointed out. You could achieve that as shown below:
protected void Button1_Click(object sender, EventArgs e)
    {
        RadGrid1.MasterTableView.SortExpressions.Clear();
        RadGrid1.MasterTableView.FilterExpression = "";
        RadGrid1.MasterTableView.GroupByExpressions.Clear();
        //bind the grid to the new datasource here and finally rebind it
        RadGrid1.Rebind();
    }

An alternative approach would be to set the visibility of the unwanted columns to false:
protected void Button1_Click(object sender, EventArgs e)
   {
       foreach (GridColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns)
       {
           if (col.UniqueName == "ShipName" || col.UniqueName == "ShipCountry")
           {
               col.Visible = false;
           }
       }
   }

That way you will be able to preserve the sorted state of the grid. Please give it a try and if the problem remains, please send us the mark-up along with the related code behind using the "Format Code Blog".

Regards,
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
Lasly
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Lasly
Top achievements
Rank 1
Share this question
or