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

Filtering on Dynamically bound grid

3 Answers 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Graham
Top achievements
Rank 1
Graham asked on 19 Nov 2012, 08:10 PM
Hi,

I'm having trouble getting the filtering to work on a RadGrid that I'm using.

I have a static RadGrid object on the .aspx page like this:
<telerik:RadGrid ID="rgCustomReport" AllowSorting="true" DataSourceID="odsCustomReport" PageSize="50"
 runat="server" OnItemCreated="rgCustomReport_ItemCreated" AllowPaging="true"
 AllowFilteringByColumn="true" EnableViewState="true"
 ShowFooter="true" AutoGenerateColumns="false" OnItemDataBound="rgCustomReport_ItemDataBound"
 Skin="WebBlue" OnPageSizeChanged="Grid_SizeChanged"
 OnSortCommand="rgCustomReport_SortCommand">
 <PagerStyle Mode="NextPrevAndNumeric" Position="TopAndBottom" AlwaysVisible="true" />
</telerik:RadGrid>

The data for this grid is bound ultimately from a DataTable.AsDataView() call on a table that is generated through many functions on every single page postback.

The filter boxes show up fine on top of each column, but when I type in a value, then hit 'Contains' (for example) I get a really weird behaviour.  And I'm not sure how to evaluate it.

After the filter is entered the grid looks like this :

http://tinyurl.com/cjf6d66

Its adding blank columns on, and filter on the wrong column.

Any help is appreciated 
Thanks!


3 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 22 Nov 2012, 09:56 AM
Hi,

Based on the event you have hooked I assume you are using simple databinding(calling DataBind method) to bind the Grid. As this help article says when you are using advanced features of RadGrid like paging, sorting, grouping, filtering, simple databinding is not supported.

If this is not the case, please elaborate a bit more about the issue and share your full page source code along with the code-behind file content.

All the best,
Andrey
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
Graham
Top achievements
Rank 1
answered on 22 Nov 2012, 06:06 PM
Hi again,
Thanks for replying!

It seems as though it just took somebody like you to tell me to look at it a little further (like it normally does).  

The grid is not being bound via a DataBind, it is actually being bound via setting the DataSourceID in the <RadGrid> tag, however, the columns are not being automatically generated.  For some reason, the person who created this, decided it would be best to add the columns manually, but let the data bind automatically via the DataSource.

So basically the DataSourceID is being used to fetch the data, but the RadGrid object itself is being passed through functions that add the columns to the RadGrid manually (I think this is why we see the extra columns in the image I linked in my first post).

If I remove where the columns are being added and let the automatically generate the columns, the filtering works fine!, although there are some columns showing up that we wish to be hidden.  I will just have to hide these columns another way which shouldn't be too difficult.

In regards to your first comment about the filtering not working when doing simple databinding,  I have used the RadGrid on many other pages, where we bind the grid in Page_Load using grid.DataSource = (some data view);grid.Rebind(); and the filtering/sorting/paging all works just fine. Just thought I'd let you know. 

Anyways I've got it all sorted out.
Thanks again
0
Andrey
Telerik team
answered on 27 Nov 2012, 01:20 PM
Hello,

Yes, most of the time the problem comes from the fact that the Grid recreates from the ViewState but the code is constantly adding new columns in addition to the ones that are restored from the ViewState.

You do not need to use AutoGenerateColumns if you don't want to you just need to check in the Page_Load event and add the columns only the first time as described in this help topic.

You could check this help topic for more information on how to customize the Grid columns.

About your last point, yes some scenarios are working with simple databinding, but because some are not and we could not guarantee the high quality of our controls this approach is not supported.

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