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.