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

[Solved] RadComboBox in FilterTemplate ?!

4 Answers 250 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Airad
Top achievements
Rank 1
Airad asked on 13 Jul 2009, 02:55 AM
<Columns> 
                  
                    <telerik:GridBoundColumn UniqueName="EmployeeNo" DataField="EmployeeNo" HeaderText="EmployeeNo" 
                        HeaderStyle-Width="200px">  
                        <FilterTemplate> 
                            <telerik:RadComboBox ID="RadComboBox1" DataTextField="EmployeeNo" DataValueField="EmployeeNo" 
                                DataSource="<%# DataBindEmployeeNo() %>" 
                                runat="server" >  
                                <Items> 
                                    <telerik:RadComboBoxItem Text="All" /> 
                                </Items> 
                            </telerik:RadComboBox> 
                            <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">  
                                <script type="text/javascript">  
                                    function EmployeeNoIndexChanged(sender,args) {  
                                        var tableView=$find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");  
                                        tableView.filter("EmployeeNo",args.get_item().get_value(),"EqualTo");  
                                    }  
                                    function RemoveItem()  
                                    {  
                                        var combo = $find("<%= RadComboBox1.ClientID %>");  
                                        var combocomboItem = combo.get_selectedItem();  
                                        if(comboItem)  
                                        {  
                                           combo.trackChanges();  
                                           combo.get_items().remove(comboItem);  
                                           combo.commitChanges();  
                                         }  
                                    }   
                                </script> 
                            </telerik:RadScriptBlock> 
                        </FilterTemplate> 
                    </telerik:GridBoundColumn> 

</
Column> 

<FilterTemplate>
                            <telerik:RadComboBox ID="RadComboBox1" >
</FilterTemplate>

I have a telerik:RadComboBox in FilterTemplate. I want to remove some items from it by client side.
I follow the demo http://www.telerik.com/help/aspnet-ajax/combo_itemsclientside.html but I can't get the combo in this way :

var combo = $find("<%= RadComboBox1.ClientID %>");  

Compiler Error Message: CS0103: The name 'RadComboBox1' does not exist in the current context

Will it be some different in FilterTemplate?

Thank you!

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 Jul 2009, 08:25 AM
Hi Airad,

Try the following approach by attaching OnclientLoad event to get the client side object of RadComboBox.

ASPX:
 
<FilterTemplate> 
    <telerik:RadComboBox ID="RadComboBox1" OnClientLoad="OnClientLoad" 
        DataTextField="CompanyName" DataValueField="CompanyName" 
        runat="server">  
        <Items> 
            <telerik:RadComboBoxItem Text="All" /> 
        </Items> 
    </telerik:RadComboBox> 
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">  
        <script type="text/javascript">   
        var combo;   
        function OnClientLoad()  
        {  
            combo =$find('<%# ((GridItem)Container).FindControl("RadComboBox1").ClientID %>');                                      
        }          
        function RemoveItem()    
        {             
            var comboItem = combo.get_selectedItem();  // Get the selected Item  
            if(comboItem)    
            {    
               combo.trackChanges();    
               combo.get_items().remove(comboItem);    
               combo.commitChanges();    
             }    
        }     
        </script> 
    </telerik:RadScriptBlock> 
</FilterTemplate> 

Thanks,
Princy.
0
Airad
Top achievements
Rank 1
answered on 14 Jul 2009, 02:18 AM
OnClientLoad="OnClientLoad" 

function OnClientLoad()  
        {  
            combo =$find('<%# ((GridItem)Container).FindControl("RadComboBox1").ClientID %>');        
            alert(combo.options.length);                                 
        }

still null

I want to remove some items form it but I just can't get this combo, any ideas o_O ?
Maybe I should remove them in another way. hohoho.

Thanks
0
Accepted
Simon
Telerik team
answered on 14 Jul 2009, 12:45 PM
Hello Airad,

You could properly get a reference to the ComboBox in Princy's approach by using the first argument of the OnClientLoad event handler:

var combo;   
  
function OnClientLoad(sender, eventArgs)   
{   
    combo = sender;                                       
}      
      
function RemoveItem()     
{              
    var comboItem = combo.get_selectedItem();  // Get the selected Item   
     
    if(comboItem)     
    {     
       combo.trackChanges();     
       combo.get_items().remove(comboItem);     
       combo.commitChanges();     
     }     


Regards,
Simon
the Telerik team

Instantly find answers to your questions on the newTelerik Support Portal.
Check out the tipsfor optimizing your support resource searches.
0
Airad
Top achievements
Rank 1
answered on 15 Jul 2009, 03:33 AM
:) Thank you, I will try.
Tags
ComboBox
Asked by
Airad
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Airad
Top achievements
Rank 1
Simon
Telerik team
Share this question
or