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

Get reference to control embedded in filter template code behind

5 Answers 779 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marty
Top achievements
Rank 1
Marty asked on 10 Mar 2009, 01:40 PM
Hi,

I'm using the following grid.  I need to get a reference to the combobox "cboGrdSysAppsFilter" that I have embedded in my filter template.  I'm not quite sure how to do it, nor can I find any articles/forum posts that directly reference this.  I've tried every way I know to access grid items, to no avail.  I'm sure it's easy, just need to be pointed in the right direction. 

Thanks,
Marty

<telerik:RadGrid OnDetailTableDataBind="GrdSysApps_DetailTableDataBind" ID="GrdSysApps" 
    runat="server" OnNeedDataSource="GrdSysApps_OnNeedDataSource" AllowMultiRowSelection="True" 
    ClientSettings-Scrolling-AllowScroll="true" AutoGenerateColumns="False" Width="99%" 
    ClientSettings-Scrolling-ScrollHeight="150" GridLines="None" ShowGroupPanel="true" 
    ClientSettings-Scrolling-SaveScrollPosition="true" ClientSettings-Scrolling-UseStaticHeaders="true" 
    AllowFilteringByColumn="true" AllowSorting="true" ClientSettings-AllowColumnsReorder="false">  
    <MasterTableView DataKeyNames="SystemApplicationID" ClientDataKeyNames="SystemApplicationID">  
        <RowIndicatorColumn> 
            <HeaderStyle Width="20px"></HeaderStyle> 
        </RowIndicatorColumn> 
        <ExpandCollapseColumn> 
            <HeaderStyle Width="20px"></HeaderStyle> 
        </ExpandCollapseColumn> 
        <Columns> 
            <telerik:GridBoundColumn DataField="SystemApplicationID" EmptyDataText="&amp;nbsp;" 
                UniqueName="column" Visible="False">  
            </telerik:GridBoundColumn> 
            <custom:CustomClientSelectColumn UniqueName="SelectedRows">  
                <FilterTemplate> 
                    <asp:DropDownList Font-Size="X-Small" ID="cboGrdSysAppsFilter" AutoPostBack="true" 
                        runat="server" OnSelectedIndexChanged="cboSelected_SelectedIndexChanged">  
                        <asp:ListItem>All</asp:ListItem> 
                        <asp:ListItem>Selected</asp:ListItem> 
                        <asp:ListItem>Not Selected</asp:ListItem> 
                    </asp:DropDownList> 
                </FilterTemplate> 
            </custom:CustomClientSelectColumn> 
            <telerik:GridBoundColumn DataField="Name" EmptyDataText="&amp;nbsp;" HeaderText="Name" 
                UniqueName="column2">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="Description" EmptyDataText="&amp;nbsp;" HeaderText="Description" 
                UniqueName="column3">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="ManagerDel" EmptyDataText="&amp;nbsp;" HeaderText="Mgr Approver" 
                UniqueName="column5">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="DirectorDel" EmptyDataText="&amp;nbsp;" HeaderText="Dir Approver" 
                UniqueName="column9">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="Director2Del" EmptyDataText="&amp;nbsp;" HeaderText="Dir2 Approver" 
                UniqueName="column6">  
            </telerik:GridBoundColumn> 
        </Columns> 
        <DetailTables> 
            <telerik:GridTableView DataKeyNames="SystemApplicationID" HierarchyLoadMode="ServerOnDemand" 
                AllowSorting="false" AllowFilteringByColumn="false" Name="OriginalOwners">  
                <ParentTableRelation> 
                    <telerik:GridRelationFields MasterKeyField="SystemApplicationID" DetailKeyField="SystemApplicationID" /> 
                </ParentTableRelation> 
                <Columns> 
                    <telerik:GridBoundColumn HeaderText="Default System Manager" HeaderButtonType="TextButton" 
                        DataField="Manager">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn HeaderText="Default System Director" HeaderButtonType="TextButton" 
                        DataField="Director">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn HeaderText="Default System 2nd Director" HeaderButtonType="TextButton" 
                        DataField="Director2">  
                    </telerik:GridBoundColumn> 
                </Columns> 
            </telerik:GridTableView> 
        </DetailTables> 
    </MasterTableView> 
    <ClientSettings AllowDragToGroup="true">  
        <Selecting AllowRowSelect="true" /> 
        <ClientEvents OnRowSelected="GrdSysApps_RowSelected" OnRowDeselected="GrdSysApps_RowDeselected" 
            OnRowCreated="GrdSysApps_RowCreated" OnCommand="RaiseCommand" /> 
    </ClientSettings> 
    <FilterMenu EnableTheming="True">  
        <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
    </FilterMenu> 
</telerik:RadGrid> 


5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 Mar 2009, 04:30 AM
Hi Marty,

Normally you can access the controls in the FilterTemplate of a column using the column's UniqueName property.I was also not able to access the control in the case of a GridClientSelectColumn. But from what I know filtering is not possisble with GridClientSelectColumn and hence I don't think FilterTemplateis required for a GridClientSelectColumn. May be Telerik can suggest a solution for this.

Thanks
Shinu
0
Marty
Top achievements
Rank 1
answered on 11 Mar 2009, 02:52 PM
The following code got the job done, as suggested, Thank you.

 foreach (GridFilteringItem filterItem in grdSysAppsRef.MasterTableView.GetItems(GridItemType.FilteringItem))  
        {  
            DropDownList combo = (DropDownList)filterItem.FindControl("cboGrdSysAppsFilter");  
         } 

Marty
0
Marty
Top achievements
Rank 1
answered on 12 Mar 2009, 07:45 PM
OK, the plans changed a bit.  Is there a way to do the same thing with client-side code?  I'm looking at the API reference and do not see a way to get the filterItems...

Anybody?

Thanks.
0
Princy
Top achievements
Rank 2
answered on 13 Mar 2009, 10:29 AM
Hello Marty,

You can place a script block with the dropdownlist in the filter template which should register the client ID of the dropdown. Then retrieve the clientId for each dropdownlist and thereby access the dropdownlist on the client event(for instance on button click). To understand better refer to the code library submission link given below:
Accessing server controls in a grid template on the client

Thanks
Princy.
0
Marty
Top achievements
Rank 1
answered on 13 Mar 2009, 06:18 PM
Thank you for the response.

I just wanted to note that I was able to find another way of doing this that was a bit easier:

I replaced my DropDownList with a RadComboBox, then wired the OnClientLoadEvent to a client-side handler to assign a reference to the combobox when it's created as seen in the help article Here.

Thanks again!

Marty
Tags
Grid
Asked by
Marty
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Marty
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or