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

Filters in RadGrid not working when page loads for first time

2 Answers 297 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amy
Top achievements
Rank 1
Amy asked on 30 Nov 2010, 04:27 PM
Hi!  I have a RadGrid which uses the FilterTemplate with a RadComboBox in GridBoundColumns.   When the page initially loads all of the filter options in the RadComboBox are not listed, however, if the page is refreshed all the options appear in the filter.

Currently the SQL statement used to initially populate the filter is in the Page_Load method, and is outside of the 'IF Not IsPostBack' logic.

 A method to refresh the combo boxes gets called in the RadGrid1_PreRender event handler.  This method takes the original SQL statement and appends a where clause which contains the value selected in the combo box by the user, after which a call to RadGrid1.MasterTableView.Rebind() is made.  The actual filtering does work as expected.

I was wondering if someone could provide some insight on how the filtering works in regards to a page initially loading, and if there is a better place to put the logic.

Thanks!

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Dec 2010, 10:56 AM
Hello Amy,

Try to populate the RadComboBox in FilterTemplate in ItemDataBound event like below and check whether it resolves the issue.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridFilteringItem)
       {
           GridFilteringItem filterItem = (GridFilteringItem)e.Item;
           RadComboBox combo = (RadComboBox)filterItem.FindControl("RadComboBox1");// accessing RadComboBox in FilterTemplate
           // Set DataSource of combo
       }
   }

Also refer the following documentation .
Filter template

Thanks,
Princy.
0
Amy
Top achievements
Rank 1
answered on 07 Dec 2010, 09:03 PM
Princy,  thank you for your reply!

I was able to get it working by putting the logic in the Page_Load and Page_PreRender methods.  Not the most elegant solution but it works.  At some point I do want to go back and try implementing your suggestion when time allows.

Thank you as always for your assistance!
Tags
Grid
Asked by
Amy
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Amy
Top achievements
Rank 1
Share this question
or