Filtering not working

16 posts, 0 answers
  1. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 27 Jan 2012 Link to this post

    I'm binding a rad grid with a data table. Whenever I use the filter, I get no results back when I know I should be getting some. Any ideas why? The sorting works fine. Here's my code.

    <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AllowPaging="True" AllowFilteringByColumn="true"
        AllowSorting="True" AutoGenerateColumns="false" PageSize="50" Height="410px" Skin="Hay">
        <MasterTableView DataKeyNames="customerId" AutoGenerateColumns="false">
             
            <Columns>
                 <telerik:GridBoundColumn DataField="Edit" HeaderText="<span style='visibility: hidden;'>a</span>" SortExpression="Edit"
                UniqueName="Edit" HeaderStyle-Width="40px" AllowFiltering="false" AllowSorting="false">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="name" HeaderText="Name" SortExpression="name"
                    UniqueName="name">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="address" HeaderText="Address" SortExpression="address"
                    UniqueName="address">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="city" HeaderText="City" SortExpression="city"
                    UniqueName="city">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="state" HeaderText="State" SortExpression="state"
                UniqueName="state">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="zip" HeaderText="Zip" SortExpression="zip"
                    UniqueName="zip">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="phone" HeaderText="Phone" SortExpression="phone"
                    UniqueName="phone">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="fax" HeaderText="Fax" SortExpression="fax"
                    UniqueName="fax">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="email" HeaderText="Email" SortExpression="email"
                    UniqueName="email">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="additional" HeaderText="Additional Info" SortExpression="additional"
                    UniqueName="additional" ItemStyle-Width="200">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
        <HeaderStyle Width="120px" />
            <ClientSettings>
                <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="True">
                </Scrolling>
            </ClientSettings>
    </telerik:RadGrid>

       Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
           If Not (Page.IsPostBack) Then
               RadGrid1.DataSource = myFunctions.customerListTable()
               RadGrid1.DataBind()
           End If
            
       End Sub
     
       Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
           RadGrid1.DataSource = myFunctions.customerListTable()
       End Sub
     
     
    'this function creates a data table for the customer list
       Public Shared Function customerListTable()
     
           Dim sql = "SELECT customerId, name, address, city, state, zip, phone, email, fax, additional FROM Customers" & _
                     " WHERE deleted = 'false' ORDER BY name"
           Dim conn As String = System.Configuration.ConfigurationManager.ConnectionStrings("connection").ToString
     
           Using myConn As New SqlConnection(conn)
     
               'create the table
               Dim myTable As New DataTable
               myTable.Columns.Add("customerId")
               myTable.Columns.Add("edit")
               myTable.Columns.Add("name")
               myTable.Columns.Add("address")
               myTable.Columns.Add("city")
               myTable.Columns.Add("state")
               myTable.Columns.Add("zip")
               myTable.Columns.Add("phone")
               myTable.Columns.Add("email")
               myTable.Columns.Add("fax")
               myTable.Columns.Add("additional")
     
               myConn.Open()
     
               Dim cmd As New SqlCommand(sql, myConn)
               Dim reader = cmd.ExecuteReader
     
     
               While reader.Read()
     
                   myTable.Rows.Add(reader("customerId"), "<a href=""../Customers/EditCustomer.aspx?id" & reader("customerId") & """>Edit</a>", _
                                    reader("name"), reader("address"), reader("city"), reader("state"), reader("zip"), _
                                    reader("phone"), reader("email"), reader("fax"), reader("additional"))
     
               End While 'while reader.read
     
               myConn.Close()
     
               Return myTable
     
           End Using 'using myConn
     
       End Function 'customerListTable












  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 29 Jan 2012 Link to this post

    Hello,

    There is not error or issue in your code then also  please remove below code and check it.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
           If Not (Page.IsPostBack) Then
               RadGrid1.DataSource = myFunctions.customerListTable()
               RadGrid1.DataBind()
           End If
             
       End Sub

    Let me know its working or not.



    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 30 Jan 2012 Link to this post

    That is not working. I already have a check for the postback in the code I posted.
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Jan 2012 Link to this post

    Hello,

    There is no need to call DataBind() method when you are binding the grid using NeedDataSource event.

    -Shinu.
  6. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 31 Jan 2012 Link to this post

    I'm not calling databind in my need data source event.

    Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
           RadGrid1.DataSource = myFunctions.customerListTable()
       End Sub
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 01 Feb 2012 Link to this post

    Hello,

    Try removing the DataBind() method in the PageLoad event. Also check the following help documentation.
    Advanced Data-binding (using NeedDataSource event).

    -Shinu.
  8. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 02 Feb 2012 Link to this post

    This is what my code looks like now, the filter still does not work. I looked at that documentation, but I don't see what I'm doing wrong. I'm not filling it with an SQL adapter and is the only real difference, I could see from your example. However, I change my code to use the sqldataadapter and fill a table but I still have the same problem. Any ideas? I can provide a link to download my project if you like.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not (Page.IsPostBack) Then
            RadGrid1.DataSource = myFunctions.customerListTable()
        End If
         
    End Sub
     
    Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
        RadGrid1.DataSource = myFunctions.customerListTable()
    End Sub
  9. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 06 Feb 2012 Link to this post

    Any help here?
  10. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 07 Feb 2012 Link to this post

    Hello,

    I recommend that you remove the data-binding of the grid on Page_Load and use Advanced Data-binding (using NeedDataSource event) only.

    Please let me know whether this helps.

    Regards,
    Mira
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  11. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 07 Feb 2012 Link to this post

    This is my code, it's almost exactly what the example shows. It's still not working.

    Imports System.Web.UI
    Imports System.Data
    Imports System.Data.Sql
    Imports System.Data.SqlClient
    Imports Telerik.Web.UI
     
    Partial Class internal_CustomerList
        Inherits System.Web.UI.Page
        Dim conn As String = System.Configuration.ConfigurationManager.ConnectionStrings("connection").ToString
     
        Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
     
            Dim sql = "SELECT * FROM CustomerList"
            Dim myconn As New SqlConnection(conn)
            Dim adapter As New SqlDataAdapter(sql, myconn)
            Dim myTable As New DataTable
            myconn.Open()
            adapter.Fill(myTable)
            myconn.Close()
     
            RadGrid1.DataSource = myTable
        End Sub
    End Class
  12. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 10 Feb 2012 Link to this post

    Hello,

    Could you please provide more information on the issue?
    Do you use the build-in filtering of the grid or custom filtering? What happens when the grid is filtered?

    Looking forward to your reply.

    Kind regards,
    Mira
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  13. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 10 Feb 2012 Link to this post

    If you look at my first post, I'm using the built in filtering. My code is very basic at this point. You can download a full copy of my site plus a backup of the db here http://dl.dropbox.com/u/4979877/site.zip The page in question is the customer list page.
  14. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 14 Feb 2012 Link to this post

    Any help here?
  15. Casey
    Casey avatar
    299 posts
    Member since:
    Jul 2009

    Posted 14 Feb 2012 Link to this post

    What filter value are you using, and for what column? If it is an alpha column and the case doesn't match, that might explain why you are not getting the expected results. 

    You may want to add GroupingSettings-CaseSensitive="false" to your RadGrid definition just to be safe.

    I hope this helps!
    Casey
  16. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 14 Feb 2012 Link to this post

    Good god, that was it, I didn't know that existed. Thanks,
  17. Casey
    Casey avatar
    299 posts
    Member since:
    Jul 2009

    Posted 14 Feb 2012 Link to this post

    No problem, it's happened to me before and it is usually the first thing I check now.

    Glad I could help!
    Casey
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017