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

Set DataTextField of RadComboBox in FilterTemplate of GridDropdowncolumn serverside

2 Answers 232 Views
Grid
This is a migrated thread and some comments may be shown as answers.
BOS
Top achievements
Rank 1
BOS asked on 14 Apr 2010, 09:51 AM

I want to set the DataTextField of a RadComboBox at pageload according to the users prefered language - and keep that value.
So far my code looks like this:
(a small part of the mastertableview of the grid RadGridVehicle)

                <telerik:GridDropDownColumn DataSourceID="sdsHaulierType" 
                                            DataField="HaulierType" DataType="System.Int32" 
                                            HeaderText="Haulier type"   
                                            ReadOnly="true" 
                                            ListTextField="HaulierTypeName"   
                                            ListValueField="HaulierTypeID"   
                                            DropDownControlType="DropDownList" 
                                            SortExpression="HaulierType" 
                                            UniqueName="HaulierType" 
                                            EditFormColumnIndex="0"   
                                            Visible="true" ForceExtractValue="Always" >  
                    <FilterTemplate>  
                        <telerik:RadComboBox ID="cbHaulierType" runat="server"   
                                             AppendDataBoundItems="true" 
                                             DataSourceID = "sdsHaulierType" 
                                             DataValueField = "HaulierTypeID" 
                                             DataTextField = "HaulierTypeName" 
                                             SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("HaulierType").CurrentFilterValue %>'  
                                             OnClientSelectedIndexChanged="HaulierTypeChanged">  
                            <Items>  
                                <telerik:RadComboBoxItem Text="All" />  
                            </Items>  
                        </telerik:RadComboBox>  
                        <telerik:RadScriptBlock ID="sbHaulierType" runat="server">  
                           <script type="text/javascript">  
                                function HaulierTypeChanged(sender,args)   
                                {  
                                    var tableView=$find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");  
                                    tableView.filter("HaulierType",args.get_item().get_value(),"EqualTo");                                      
                                }  
                            </script>   
                        </telerik:RadScriptBlock>  
                    </FilterTemplate>  
                </telerik:GridDropDownColumn> 

I'm using a table called HaulierType with the following columns:
  • HaulierTypeID (PK)
  • HaulierTypeName (default column for DataTextField in the RadComboBox)
  • SVHaulierType
  • DAHaulierType
    <asp:SqlDataSource ID="sdsHaulierType" runat="server"   
                       ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"   
                       SelectCommand="SELECT * FROM [HaulierType]">  
    </asp:SqlDataSource> 

I can get the grid to show the correct values like this:
protected void RadGridVehicle_Load(object sender, EventArgs e)  
    {  
        ddc = (GridDropDownColumn)RadGridVehicle.MasterTableView.Columns.FindByUniqueName("HaulierType");  
        if (userLang == "da")  
        {  
            ddc.ListTextField = "DAHaulierType";  
        }  
        else if (userLang == "sv")  
        {  
            ddc.ListTextField = "SVHaulierType";  
        }  
    } 

What's missing is setting the filtervalues in the gridcolumn.
How do I set the DataTextField serverside and in which event?

Please help - I'm totally stock.

2 Answers, 1 is accepted

Sort by
0
Accepted
Iana Tsolova
Telerik team
answered on 14 Apr 2010, 03:58 PM
Hello BOS,

You can handle the ItemCreated event of RadGrid and there find the desired RadComboBox, as shown below for instance:

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridFilteringItem)
    {
        GridFilteringItem item = e.Item as GridFilteringItem;
        RadComboBox filterCombo = item["HaulierType"].FindControl("sbHaulierType") as RadComboBox;
    }
}

For more information on how to access RadGrid cells and rows, you can refer to the below article:

http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html

Kind regards,
Iana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
BOS
Top achievements
Rank 1
answered on 15 Apr 2010, 07:07 AM
Thanks - that did the trick :-)

Final code:
    protected void RadGridVehicle_ItemCreated(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridFilteringItem)  
        {  
            GridFilteringItem item = e.Item as GridFilteringItem;  
            RadComboBox filterCombo = item["HaulierType"].FindControl("cbHaulierType") as RadComboBox;  
            if (userLang == "da")  
            {  
                filterCombo.DataTextField = "DAHaulierType";  
            }  
            else if (userLang == "sv")  
            {  
                filterCombo.DataTextField = "SVHaulierType";  
            }  
        }  
    }   

Should I place the code for the ListTextField of the GridDropDownColumn in the same event?
Tags
Grid
Asked by
BOS
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
BOS
Top achievements
Rank 1
Share this question
or