Hello,
I am using the server-side method for using a Filter Template with a RadComboBox on a RadGrid. I have it working using this method but how do I set the SelectedValue of the RadComboBox using this method? The client-side method has some Eval code in the control on the page but that doesn't work for the server-side method. I assumed I would set the SelectedValue property of the RadComboBox in the codebehind during the RadComboBox_SelectedIndexChanged method but I can't seem to make it work. Maybe because I don't know how to access the RadComboBox control properly?
thanks,
Steve
I am using the server-side method for using a Filter Template with a RadComboBox on a RadGrid. I have it working using this method but how do I set the SelectedValue of the RadComboBox using this method? The client-side method has some Eval code in the control on the page but that doesn't work for the server-side method. I assumed I would set the SelectedValue property of the RadComboBox in the codebehind during the RadComboBox_SelectedIndexChanged method but I can't seem to make it work. Maybe because I don't know how to access the RadComboBox control properly?
thanks,
Steve
5 Answers, 1 is accepted
0
Hi Stephen,
From the server side perspective, once an item in the RadComboBox is selected, and the SelectedIndexChanged event is raised, you can get the new value, and set the filter expression of the control accordingly like that:
For further information and code-samples, you can browse this help article which illustrates how to use RadComboBox in a FilterTemplate.
Greetings,
Tsvetina
the Telerik team
From the server side perspective, once an item in the RadComboBox is selected, and the SelectedIndexChanged event is raised, you can get the new value, and set the filter expression of the control accordingly like that:
protected
void
FilterCombo_SelectedIndexChanged(
object
o, RadComboBoxSelectedIndexChangedEventArgs e)
{
string
filterExpression;
filterExpression =
"([CategoryName] = '"
+ e.Value +
"')"
;
RadGrid1.MasterTableView.FilterExpression = filterExpression;
RadGrid1.MasterTableView.Rebind();
}
For further information and code-samples, you can browse this help article which illustrates how to use RadComboBox in a FilterTemplate.
Greetings,
Tsvetina
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
Stephen
Top achievements
Rank 1
answered on 16 Aug 2010, 02:41 PM
Hi,
I have the filter expression working correctly as you have described below. My problem is that once the page posts back, the item of the radcombobox that was selected does not stay selected, it goes back to the first item in the list. I need to make the correct item in the radcombobox stay selected after the page posts back.
thanks,
Steve
I have the filter expression working correctly as you have described below. My problem is that once the page posts back, the item of the radcombobox that was selected does not stay selected, it goes back to the first item in the list. I need to make the correct item in the radcombobox stay selected after the page posts back.
thanks,
Steve
0
Accepted
Hi Stephen,
The reason for this to happens is that once Rebind() is called on RadGrid all the controls inside it are recreated and the RadComboBox state is lost. In order to persist the SelectedValue, you can keep it in the ViewState and set it to the control in its PreRender event handler:
I hope this helps.
Kind regards,
Tsvetina
the Telerik team
The reason for this to happens is that once Rebind() is called on RadGrid all the controls inside it are recreated and the RadComboBox state is lost. In order to persist the SelectedValue, you can keep it in the ViewState and set it to the control in its PreRender event handler:
protected
void
RadComboBox1_SelectedIndexChanged(
object
sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
RadComboBox combo = sender
as
RadComboBox;
ViewState[combo.ClientID] = e.Value;
string
filterExpression;
filterExpression =
"([ShipCity] = '"
+ e.Value +
"')"
;
RadGrid1.MasterTableView.FilterExpression = filterExpression;
RadGrid1.MasterTableView.Rebind();
}
protected
void
RadComboBox1_PreRender(
object
sender, EventArgs e)
{
RadComboBox combo = sender
as
RadComboBox;
if
(ViewState[combo.ClientID] !=
null
)
{
combo.SelectedValue = ViewState[combo.ClientID].ToString();
}
}
I hope this helps.
Kind regards,
Tsvetina
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
Stephen
Top achievements
Rank 1
answered on 18 Aug 2010, 03:17 PM
Perfect! Thank you!
0
Naga
Top achievements
Rank 1
answered on 23 Jul 2013, 02:39 PM
thank you very much.