I have a grid that is being populated OnNeeddDataSource
In this grid the client column has a Filter Template that is a RadComboBox
This all works fine except when I try to sort on the grid when I have set a filter. The data in the grid is correct but the DropDown gets changed to *** ALL ***.
I have tried the following code to select the by value
Is there a way to keep the selected value in the combobox when the grid gets reloaded on sort?
<
telerik:RadGrid
runat
=
"server"
ID
=
"RadGrid1"
AllowPaging
=
"True"
AllowSorting
=
"True"
PageSize
=
"20"
AllowFilteringByColumn
=
"True"
EnableViewState
=
"False"
AutoGenerateColumns
=
"False"
Skin
=
"Office2007"
GridLines
=
"None"
OnItemCreated
=
"RadGrid1_ItemCreated"
OnPreRender
=
"RadGrid1_PreRender"
OnNeedDataSource
=
"PC_NeedDataSource"
>
In this grid the client column has a Filter Template that is a RadComboBox
<
telerik:GridBoundColumn
SortExpression
=
"ClientName"
DataField
=
"ClientName"
HeaderText
=
"Client Name"
HeaderStyle-Width
=
"300px"
>
<
FilterTemplate
>
<
telerik:RadComboBox
ID
=
"RadComboBoxClientName"
DataTextField
=
"ClientName"
DataValueField
=
"ClientName"
AppendDataBoundItems
=
"true"
SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("ClientName").CurrentFilterValue %>' runat="server" OnClientSelectedIndexChanged="ClientNameIndexChanged" Skin="Office2007">
</
telerik:RadComboBox
>
<
telerik:RadScriptBlock
ID
=
"RadScriptBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function ClientNameIndexChanged(sender, args) {
var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
if (args.get_item().get_value() == "0") { tableView.filter("ClientName", args.get_item().get_value(), "NoFilter");
}
else {
tableView.filter("ClientName", args.get_item().get_value(), "EqualTo");
}
}
</
script
> </
telerik:RadScriptBlock
>
</
FilterTemplate
>
</
telerik:GridBoundColumn
>
This all works fine except when I try to sort on the grid when I have set a filter. The data in the grid is correct but the DropDown gets changed to *** ALL ***.
I have tried the following code to select the by value
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridFilteringItem)
{
GridFilteringItem filterItem = (GridFilteringItem)e.Item;
RadComboBox combo = (RadComboBox)filterItem["ClientName"].FindControl("RadComboBoxClientName");
if (Session["AdvisorClientID"] == null)
{
ClientDataContext db = new ClientDataContext();
var clients = (from c in db.Clients
select new
{
c.ClientID,
c.ClientName,
})
.OrderBy(c => c.ClientName);
combo.DataSource = clients;
RadComboBoxItem newItem = new RadComboBoxItem();
newItem.Text = "*** ALL ***";
newItem.Value = "0";
combo.Items.Insert(0, newItem);
int test = RadGrid1.MasterTableView.FilterExpression.IndexOf("ClientName = \"");
if (test > 0)
{
string clientName = RadGrid1.MasterTableView.FilterExpression.Replace("(ClientName = \"", "");
clientName = clientName.Replace("\")", "");
combo.SelectedValue = clientName;// combo.FindItemByValue(clientName);
}
}
else
{
combo.Visible = false;
}
}
}
Is there a way to keep the selected value in the combobox when the grid gets reloaded on sort?