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

[Solved] Filter by RadComboBox ?

5 Answers 203 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Airad
Top achievements
Rank 1
Airad asked on 09 Jul 2009, 08:51 AM
aspx:

<
Columns> 
               <telerik:GridBoundColumn UniqueName="EmployeeNo" DataField="EmployeeNo" HeaderText="EmployeeNo" HeaderStyle-Width="200px">  
                        <FilterTemplate> 
                            <telerik:RadComboBox ID="RadComboBox1" DataTextField="EmployeeNo" 
                                DataValueField="EmployeeNo" Height="100px" AppendDataBoundItems="true" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("EmployeeNo").CurrentFilterValue %>' 
                                runat="server" OnClientSelectedIndexChanged="EmployeeNoIndexChanged">  
                                <Items> 
                                    <telerik:RadComboBoxItem Text="All" /> 
                                    <telerik:RadComboBoxItem Text="000000" Value="000000"/>  //add item in aspx
                                </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");  
                                    }  
                                </script> 
                            </telerik:RadScriptBlock> 
                        </FilterTemplate> 
                </telerik:GridBoundColumn> 
</Columns> 

cs:

protected
 void Page_Load(object sender, EventArgs e)  
        {  
            if (!Page.IsPostBack)  
            {  
 
                RadComboBox RadComboBox1 = this.FindControl("RadComboBox1"as RadComboBox;  
                RadComboBox1 = new RadComboBox();  
                RadComboBoxItem item = new RadComboBoxItem();  
 
                item.Text = "000001";  
                item.Value = "000001";  
 
                RadComboBox1.Items.Add(item);  
 
                RadComboBox1.DataBind();  
        } 

I want to filter the grid by a RadComboBox.
I tried as demo (http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filtertemplate/defaultcs.aspx) but RadComboBox in this demo binding data by DataSourceID and <asp:SqlDataSource>.

I want to bind data from aspx.cs in this way when first page load:

RadComboBox1.Items.Add(item);  
RadComboBox1.DataBind();  

But I find that I can't  bind data like this  o_O !

<telerik:RadComboBoxItem Text="000000" Value="000000"/>  // only can add item like this in aspx
how to do this  '-' ?

thanks!

5 Answers, 1 is accepted

Sort by
0
Accepted
Pavlina
Telerik team
answered on 09 Jul 2009, 04:21 PM
Hello Airad,

Attached to this message is a simple runnable application which handles the desired functionality. Please give it a try and see if it works for you or if I am leaving something out.

Greetings,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Airad
Top achievements
Rank 1
answered on 10 Jul 2009, 05:05 AM
: )  I'm sorry I didn't describe the situation clearly.

As our coding stander, it's not available for me to binding data to combobox like DataSourceID="SqlDataSource1" ' in ASPX.

So I have to bind in this way in CS:

protected void Page_Load(object sender, EventArgs e)
{

    RadComboBox RadComboBox1 = this.FindControl("RadComboBox1") as RadComboBox;

    RadComboBox1 = new RadComboBox();


    RadComboBox1.DataTextField = "EmployeeNo";
    RadComboBox1.DataValueField = "EmployeeNo";
    RadComboBox1.DataSource = DataGetAll();  // a method to get data
}

And this telerik:RadComboBox is in the FilterTemplate:
<telerik:GridBoundColumn>
                        <FilterTemplate>
                                <telerik:RadComboBox> </telerik:RadComboBox>
                        </FilterTemplate>
</telerik:GridBoundColumn>

Can you tell me how to bind data in this situation ?

Thanks!
0
Airad
Top achievements
Rank 1
answered on 10 Jul 2009, 06:10 AM
I also tried OnItemsRequested="RadComboBox_ItemsRequested" to bind data in <telerik:RadComboBox>, but it seems that does not come to control to .cs page o_O!
0
Shinu
Top achievements
Rank 2
answered on 10 Jul 2009, 06:21 AM
Hi Airad,

Try accessing the RadCombobox in the ItemDataBound event and then bind the Combobox as shown below.

CS:
 
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridFilteringItem) 
        { 
            GridFilteringItem filteritem = (GridFilteringItem)e.Item; 
            RadComboBox RadComboBox1 = (RadComboBox)filteritem.FindControl("RadComboBox1"); 
 
            RadComboBox1.DataTextField = "EmployeeNo"
            RadComboBox1.DataValueField = "EmployeeNo"
            RadComboBox1.DataSource = DataGetAll();  // a method to get data 
        } 
    } 


Thanks
Shinu
0
Airad
Top achievements
Rank 1
answered on 10 Jul 2009, 07:55 AM
Thanks, I find another method!

aspx:
<telerik:RadComboBox ID="RadComboBoxCountry" DataTextField="EmployeeNo" DataValueField="EmployeeNo" DataSource="<%# DataBindEmployeeNo() %>"  runat="server" >

cs:
protected TList<Employee> DataBindEmployeeNo()
{
            return DataGetAll(); // a method to return a datasource
}

: )  I just confused before.
Tags
Grid
Asked by
Airad
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Airad
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or