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

Get SelectedValue of RadComboBox in FilterTemplate of GridTemplateColumn in RadGrid

9 Answers 274 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Celeste
Top achievements
Rank 1
Celeste asked on 23 Nov 2010, 09:59 PM
Dear Forum,

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

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Nov 2010, 06:40 AM
Hello,


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.
0
Celeste
Top achievements
Rank 1
answered on 24 Nov 2010, 02:33 PM
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
0
Tsvetina
Telerik team
answered on 26 Nov 2010, 03:46 PM
Hello 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
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Celeste
Top achievements
Rank 1
answered on 29 Nov 2010, 03:17 PM
Tsvetina,

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
0
Tsvetina
Telerik team
answered on 30 Nov 2010, 03:05 PM
Hi 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
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Celeste
Top achievements
Rank 1
answered on 30 Nov 2010, 04:21 PM
Here is the code for the filter template and  combo box selection handling :

<

 

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);
            }
        }

0
Tsvetina
Telerik team
answered on 03 Dec 2010, 12:41 PM
Hi Celeste,

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
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Celeste
Top achievements
Rank 1
answered on 03 Dec 2010, 03:27 PM
Tsvetina,

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
0
Accepted
Tsvetina
Telerik team
answered on 06 Dec 2010, 10:49 AM
Hi 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
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Ajax
Asked by
Celeste
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Celeste
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or