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

Dropdowncolumn with serverside radcombobox

1 Answer 68 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:47 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.

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 14 Apr 2010, 03:57 PM
Hi 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 articles:

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


Sincerely yours,
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.
Tags
Grid
Asked by
BOS
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or