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

Grid Filtering using Filter expression

1 Answer 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Venkatesh
Top achievements
Rank 1
Venkatesh asked on 01 Feb 2011, 01:35 PM
Hi,

     I am facing a issue while filter a radgrid. I have a filter Expression written in my program and that is throwing some exception while runing. Please solve me this issue ASAP. I will attach my code here with the exception message what I am facing while Running.
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
      
      
        <script type="text/javascript">
            function showMenu(e) {
                var contextMenu = $find("<%= RadContext.ClientID %>");
  
                contextMenu.show(e);
            }
            var combo;
            function OnClientLoad(sender, args) {
                 combo = sender;
            }
            function getFilterComboBox() {
                  
                var comboItem = combo.get_selectedItem();  // combo represents the FilterCombo 
                document.getElementById('<%=hdnRadCombo.ClientID %>').value = comboItem._text;
            
  
</script>
    <telerik:RadGrid runat="server" ID="JobSummaryGrid" AllowFilteringByColumn="true"
            AutoGenerateColumns="false">
    <MasterTableView AllowFilteringByColumn="true" AllowSorting="true" AllowPaging="true">
      <Columns>
              
            <telerik:GridBoundColumn DataField="header" DataType="System.String" HeaderText="Header"
             UniqueName="Header" FilterControlWidth="70px">
            </telerik:GridBoundColumn>
  
            <telerik:GridBoundColumn DataField="details" DataType="System.String" HeaderText="details" 
            UniqueName="details" FilterControlWidth="70px">
            </telerik:GridBoundColumn>
  
            <telerik:GridBoundColumn DataField="orgin" DataType="System.String" HeaderText="orgin"
             UniqueName="orgin" FilterControlWidth="70px">
            </telerik:GridBoundColumn>
  
            <telerik:GridBoundColumn DataField="contenttitle" DataType="System.String" HeaderText="contenttitle"
             UniqueName="contenttitle" FilterControlWidth="70px" >
            </telerik:GridBoundColumn>
  
            <telerik:GridBoundColumn DataField="JoinDate" DataType="System.DateTime" HeaderText="JoinDate"
             UniqueName="JoinDate" FilterControlWidth="70px">
            </telerik:GridBoundColumn>
  
            <telerik:GridBoundColumn DataField="serviceType" DataType="System.String" HeaderText="serviceType"
             UniqueName="serviceType" FilterControlWidth="70px" ShowFilterIcon="true" AllowFiltering="true">
             <FilterTemplate>
                <telerik:RadComboBox runat="server" ID="radCombobox1" DataTextField="serviceType"
                 DataValueField="serviceType" OnClientLoad="OnClientLoad" OnClientSelectedIndexChanged="getFilterComboBox">
                <Items>
                    <telerik:RadComboBoxItem Text="serviceType1" />
                    <telerik:RadComboBoxItem Text="serviceType2" />
                    <telerik:RadComboBoxItem Text="serviceType3" />
                </Items>
                </telerik:RadComboBox>                
                 
                <img src="FilterIcon.JPG" alt="Landscape" width="22px" onclick="showMenu(event)" />
                     
                <asp:ImageButton runat="server" ID="imgButtonClearFilter" ImageUrl="~/ClearFilter.jpeg" OnClick="clearFilter" />
             </FilterTemplate>
             </telerik:GridBoundColumn>
      </Columns>        
    </MasterTableView>
    </telerik:RadGrid>
    <telerik:RadScriptManager runat="server">
    </telerik:RadScriptManager>
    <telerik:RadContextMenu runat="server" ID="RadContext" 
            onitemclick="RadContext_ItemClick">
    <Items>
        <telerik:RadMenuItem Text="EqualTo"/>
    </Items>
    </telerik:RadContextMenu>
    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
     <asp:HiddenField ID="hdnRadCombo" runat="server" />
</asp:Content>
protected void RadContext_ItemClick(object sender, RadMenuEventArgs e)
    {
        radComboboxSelectedString = hdnRadCombo.Value;
        switch (e.Item.Text)
        {
            case "EqualTo":
  
                foreach (GridBoundColumn column in JobSummaryGrid.MasterTableView.Columns)
                {
                    if (column.UniqueName == "serviceType")
                    {                       
                        JobSummaryGrid.MasterTableView.FilterExpression = "(Convert.ToString(it[serviceType])=" + radComboboxSelectedString + ")";//"it.serviceType ="+radComboboxSelectedString+"";
                        //JobSummaryGrid.MasterTableView.FilterExpression = "(it"+"[ Header]"+".ToString().StartsWith("+"6"+"))";
                        column.CurrentFilterFunction = GridKnownFunction.EqualTo;
                        JobSummaryGrid.MasterTableView.Rebind();
                          
                    }
                }
                break;
        }
    }  

1 Answer, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 01 Feb 2011, 05:39 PM
Hi Venkatesh,

The format of the filter expression depends on the version of .NET Framework you are using and the type of the datasource. Have a look at the end of this help article for the correct format in your case. Note that if you are using .NET 3.5 or later the value of the EnableLinqExpressions property should be true otherwise set it to false. Also have in mind that the name of the field that we filter on should be enclosed in quotation marks which should be escaped with backslash like that:
"(Convert.ToString(it[\"CustomerID\"]) = \"ALFKI\")";

All the best,
Marin
the Telerik team
Browse the vast support resources we have to jump start 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
Grid
Asked by
Venkatesh
Top achievements
Rank 1
Answers by
Marin
Telerik team
Share this question
or