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

RadGrid - Using a RadSearchBox in a FilterTemplate (and also using OpenAccess)

4 Answers 217 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Calsh
Top achievements
Rank 1
Calsh asked on 10 Oct 2013, 11:58 PM

Trying to use a RadSearchBox in a FilterTemplate while using OpenAccess (I believe using simple binding?)  -  not sure how to get the filtering to work/in code behind - looked at several samples/demos - but none seem to show how or if it will work when using OpenAccess (trying to stick with simple binding if possible)

Test code below

 

 

<telerik:RadGrid ID="RadGridResults" runat="server" AutoGenerateColumns="False"
 
 CellSpacing="0" DataSourceID="OpenAccessLinqDataSource"
 
 GridLines="None" AllowPaging="True"
 
 AllowSorting="True" EnableLinqExpressions="False"
 
 AllowFilteringByColumn="True">
 
 <ClientSettings>
 
 <Scrolling AllowScroll="True" UseStaticHeaders="True" />
 
 </ClientSettings>
 
 <MasterTableView DataKeyNames="ProductID"
 
 DataSourceID="OpenAccessLinqDataSource1">
 
 <Columns>
 
 <telerik:GridBoundColumn DataField="ProductRef" FilterControlAltText="Filter Product Ref column"
 
 HeaderText="ProductRef" SortExpression="ProductRef" UniqueName="ProductRef">
 
 </telerik:GridBoundColumn>
 
 <telerik:GridDropDownColumn FilterControlAltText="Filter Brand Name column" UniqueName="ProductBrandName"
 
 DataSourceID="OpenAccessLinqDataSourceBrandName" DataField="ProductBrandNameID"
 
 HeaderText="Brand Name" SortExpression="CompanyName" ListValueField="CompanyID"
 
 AllowSorting="true" ListTextField="CompanyName" DropDownControlType="DropDownList">
 
 <FilterTemplate>
 
 <telerik:RadSearchBox ID="RadSearchBox1" runat="server" DataSourceID="OpenAccessLinqDataSourceBrandName"
 
 DataTextField="CompanyName" DataValueField="CompanyID" ShowSearchButton="False" OnSearch="RadSearchBox1_Search">
 
 </telerik:RadSearchBox>
 
 </FilterTemplate>
 
 </telerik:GridDropDownColumn>

Tried using code below but DataBind() causes error 'Expression Expected' - have set 'EnableLinqExpressions=False' - as per other threads/samples

 

 

 

Protected Sub RadSearchBox1_Search(sender As Object, e As SearchBoxEventArgs)
 
 RadGridResults.MasterTableView.FilterExpression = "([ProductBrandName] = " + e.Text + ")"
 
 Dim column As GridColumn = RadGridResults.MasterTableView.GetColumnSafe("ProductBrandName")
 
 column.CurrentFilterFunction = GridKnownFunction.EqualTo
 
 column.CurrentFilterValue = e.Text
  
 RadGridResults.DataBind()
  
 End Sub

 

 

 

 


4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Oct 2013, 05:49 AM
Hi Calsh,

Please try the following code snippet to filter using RadSearchBox.

VB:
Protected Sub RadSearchBox1_Search(sender As Object, e As SearchBoxEventArgs)
    Dim filterExpression As String
    filterExpression = "([ProductBrandName] = '" + e.Value + "')"
    RadGridResults.MasterTableView.FilterExpression = filterExpression
    RadGridResults.MasterTableView.Rebind()
End Sub

Thanks,
Princy
0
Calsh
Top achievements
Rank 1
answered on 11 Oct 2013, 08:48 AM
Hi

Still getting the same error 'Expression Expected' at lineRadGridResults.MasterTableView.Rebind()

Thanks
0
Princy
Top achievements
Rank 2
answered on 11 Oct 2013, 08:59 AM
Hi ,

Below is the sample code that i tried,and it works fine at my end,can you try removing the square brackets of([ProductBrandName ]) and try if it helps.

ASPX:
<telerik:RadGrid ID="RadGridResults" runat="server" EnableLinqExpressions="False">
    <MasterTableView >
        <Columns>           
            <telerik:GridDropDownColumn UniqueName="ShipCountry" DataSourceID="OpenAccess"
                DataField="ShipCountry" HeaderText="ShipCountry" ListValueField="ShipCountry"
                ListTextField="ShipCountry" DropDownControlType="DropDownList">
                <FilterTemplate>
                    <telerik:RadSearchBox ID="RadSearchBox1" runat="server" DataSourceID="OpenAccess"
                        DataTextField="ShipCountry" DataValueField="ShipCountry" ShowSearchButton="False"
                        OnSearch="RadSearchBox1_Search">
                    </telerik:RadSearchBox>
                </FilterTemplate>
            </telerik:GridDropDownColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

VB:
Protected Sub RadSearchBox1_Search(sender As Object, e As SearchBoxEventArgs)
    Dim filterExpression As String
    filterExpression = "(ShipCountry = '" + e.Value + "')"
    RadGridResults.MasterTableView.FilterExpression = filterExpression
    RadGridResults.MasterTableView.Rebind()
End Sub

Thanks,
Princy
0
Calsh
Top achievements
Rank 1
answered on 15 Oct 2013, 10:42 AM
Hi

Sorry for not replying earlier

Yes - removing the square brackets worked

Thanks for your help
Tags
Grid
Asked by
Calsh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Calsh
Top achievements
Rank 1
Share this question
or