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

[Solved] How to access FilterTemplate at server side.

3 Answers 306 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 08 Apr 2009, 12:40 PM
Hi all,

        I am using FilterTemplate to one of the column at clientside binding as :

<telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name"
                        UniqueName="Name">
                        <FilterTemplate>
                        <telerik:RadComboBox ID="radFilterComboBox" DataTextField="Name" runat="server" AutoPostBack="true" ShowToggleImage="true" 
                                             OnSelectedIndexChanged="radFilterComboBox_SelectedIndexChanged" Skin="Office2007" 
                                             Width="300" OnItemsRequested="radFilterComboBox_ItemsRequested">
                        </telerik:RadComboBox> 
                        </FilterTemplate>
                    </telerik:GridBoundColumn>

  1)    Now i need to populate this ComboBox with the Names which are in Name field(shown). And by the way i am not using SqlDataSource, instead using LINQ queries to bind grid at server side.

  2)   How to access this "radFilterComboBox" at codebehind in page_load. 

        Thanks in advance. 

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 Apr 2009, 05:32 AM
Hi Josh,

Try accessing the ComboBox from the filterTemplate in the PreRender event of the Grid.

CS:
 
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridFilteringItem filter in RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)) 
        { 
            RadComboBox combo = (RadComboBox)filter.FindControl("radFilterComboBox"); 
            //populate the combobox 
        } 
    } 

Thanks
Shinu
0
David
Top achievements
Rank 1
answered on 25 Jan 2010, 10:29 PM
I am trying this and the width items works fine, but the Skin is not being applied.
I am using an Application variable because the users are allowed to pick a skin they like in setup.
Any thing i am missing ?

 

 

For Each filter As GridFilteringItem In rgQuotes.MasterTableView.GetItems(GridItemType.FilteringItem)  
 
 
 
 
'populate the combobox   
 
Dim StatusDDL As RadComboBox = DirectCast(filter.FindControl("RadComboBoxStatus"), RadComboBox)  
 
StatusDDL.Width = Unit.Pixel(100)  
 
StatusDDL.DropDownWidth = Unit.Pixel(160)  
 
StatusDDL.Skin = Application("TelerikTheme")  
 
 
 
Next  
 

 

0
David
Top achievements
Rank 1
answered on 27 Jan 2010, 02:17 PM
I got this to work but i don't understand why.

The code i called - after the piece I posted above - was a dfault sort.

        'DEFAULT SORT   
        If Not Page.IsPostBack Then  
            Dim expression As GridSortExpression = New GridSortExpression()  
            expression.FieldName = "QuoteDate" 
            expression.SortOrder = GridSortOrder.Descending  
            rgQuotes.MasterTableView.SortExpressions.AddSortExpression(expression)  
            rgQuotes.MasterTableView.Rebind()  
        End If 

This code has a rebind call.   if it runs before the code for the filter, the conbobox is skinned,  if it runs after, it is not.

Similarly I have some javascript from the forum that will show or hide the filter row based on  a radio button selection, a cookie on page load.
            <script type="text/javascript">  
 
                function pageLoad(sender, eventArgs) {  
 
                    var filter = getCookie("filter");  
                    if (filter != "on")  
                        $find('<%=rgQuotes.ClientID %>').get_masterTableView().hideFilterItem();  
                    //$find('<%=rgQuotes.ClientID %>').get_masterTableView().rebind();  
 
                }  
 
                function showFilterItem() {  
 
                    var masterTable = $find("<%= rgQuotes.ClientID %>").get_masterTableView();  
                    masterTable.showFilterItem();  
                    //masterTable.rebind();  
                    setCookie("filter", "on", 7);  
 
                }  
                function hideFilterItem() {  
 
                    var masterTable = $find("<%= rgQuotes.ClientID %>").get_masterTableView();  
                    masterTable.hideFilterItem();  
                    //masterTable.rebind();  
                    setCookie("filter", "off", 7);  
                }   
            </script> 


The 3 functions called rebind and made the client side ajax loading graphic fire. I took out the rebind calls and the hiding/showing of filter row still worked but  the skins went away. 

The place i could not remove the rebind was the Default filter, or it didn;t actually sort it.


So I guess it seems necessary, but i guess my question is where is the most efficient place to call rebind and make sure my customizations all work, and so i only call it once !!   In the first build of this I would have been calling it 2-3 times per page.


Tags
Grid
Asked by
Josh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
David
Top achievements
Rank 1
Share this question
or