Please assist! I have created a RadGrid with GridTemplateColumns where the FilterTemplates contain RadComboBoxes. I cannot figure out how to access the selected value or item of the RadComboBox in codebehind (C#) and I need to do this on the RadGrid's _ItemCommand event for this criteria if (e.CommandName == Telerik.Web.UI.RadGrid.FilterCommandName).
No clue, and I've read everything I can find.
Celeste
9 Answers, 1 is accepted

There is a documentation which shows how to use RadComoBox in FilrterTemplate of Grid. Hope this is what you are searching for.
Filter template
-Shinu.

No, that is not what I am looking for. I've already read through and tried that. Please just re-read my post and if you can help it would be appreciated.
Celeste
In this case, if you filter through firing a filter command, you can try accessing the RadComboBox in the following way:
protected
void
RadGrid1_ItemCommand(
object
source, GridCommandEventArgs e)
{
if
(e.CommandName == RadGrid.FilterCommandName)
{
Pair filterPair = (Pair)e.CommandArgument;
RadComboBox filterBox = (e.Item
as
GridFilteringItem)[filterPair.Second.ToString()].Controls[0]
as
RadComboBox;
string
value = filterBox.SelectedValue;
}
All the best,
Tsvetina
the Telerik team

Yes, I tried that approach but the RadComboBox filterBox is null after that line of code, so I get the "Object reference not set to an instance of an object" error.
Celeste
Could you please share the code that you are using to set up the described scenario - the filter template, combo box selection handling, etc, so we can provide you with a solution relevant to your specific scenario?
Greetings,
Tsvetina
the Telerik team

<
telerik:GridTemplateColumn DataField="AccountName" HeaderText="Account Name"
UniqueName="AccountName" GroupByExpression="AccountName Group By AccountName"
SortExpression="AccountName" >
<FilterTemplate>
<telerik:RadComboBox ID="rcbAccountName" DataSourceID="SDSAccountName"
EnableTheming="false" DataTextField="AccountName" Font-Size="X-Small"
DataValueField="AccountName" Height="200px" AppendDataBoundItems="true"
SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("AccountName").CurrentFilterValue %>'
runat="server" OnClientSelectedIndexChanged="AccountNameChanged"
EnableAutomaticLoadOnDemand="False" >
<Items>
<telerik:RadComboBoxItem EnableTheming="false" Font-Size="X-Small" />
</Items>
</telerik:RadComboBox>
<telerik:RadScriptBlock ID="rsbAccountName" runat="server">
<script type="text/javascript">
function AccountNameChanged(sender, args) {
var tableView=$find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
tableView.filter(
"AccountName", args.get_item().get_value(), "EqualTo");
}
</script>
</telerik:RadScriptBlock>
</FilterTemplate>
<ItemTemplate>
<%
# Eval("AccountName")%>
</ItemTemplate>
</telerik:GridTemplateColumn>
What I need to do with the information is construct a list of the filter expressions for the user -- they get added to a bulleted list:
protected void rgAccounts_ItemCommand(object source, GridCommandEventArgs e)
{
string msg;
if (e.CommandName == Telerik.Web.UI.RadGrid.FilterCommandName)
{
Pair filterPair = (Pair)e.CommandArgument;
msg = String.Concat("Filter: '", filterPair.First, "' for ", filterPair.Second, "; ");
RadComboBox thisRCB = ((RadComboBox)(e.Item as GridFilteringItem)[filterPair.Second.ToString()].Controls[0]);
string strThisSelectedItem = thisRCB.SelectedItem.ToString();
string strThisSelectedValue = thisRCB.SelectedValue.ToString();
string strThisText = thisRCB.Text;
string filterPattern = ((TextBox)(e.Item as GridFilteringItem)[filterPair.Second.ToString()].Controls[0]).Text;
msg = String.Concat(msg, "Search Pattern: '", filterPattern, "'");
// if there is an item in the list that starts with "Filter: " and the same first 11 chars of filterPair.first, then delete it
String filterColumn = filterPair.Second.ToString();
for (int i = 0; i < blistMessages.Items.Count; i++)
{
ListItem li = blistMessages.Items[i];
if (li.Text.Contains(filterPair.Second.ToString()))
{
blistMessages.Items.Remove(li);
}
}
AddMessageToList(this.rgAccounts.MasterTableView.FilterExpression);
}
}
Have you tried debugging your code in item command to see what is inside the Controls collection of the filtering item? I created a sample grid with your template column declaration and the RadComboBox was actually in (e.Item as GridFilteringItem)["ColumnUnuiqueName"].Controls[1], not Controls[0]. The other option is to try and use FindControl() in order to get a reference to the combo.
Best wishes,
Tsvetina
the Telerik team

Thank you, Controls[1] resolved the issue. But I would appreciate if you could screenshot for me of how you found the controls collection when you debugged, try as I may, I could not work out how to drill into (e.Item as GridFilterinItem) and find the collection. Can you post a screenshot to show how to find the collection during debug?
Thanks,
Celeste
You can easily examine the Controls collection by using the Quick Watch dialog box in Visual Studio by checking first the length of the collection and if it is larger than 0 - checking each index separately. You can read more on Quick Watch at that address. Additionally, I attach a screenshot demonstrating how I inspected the filtering item.
Kind regards,
Tsvetina
the Telerik team