Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Grid Filtering

Grid Filtering

Scheduled Pinned Locked Moved Visual Basic
questioncsharpcssdatabase
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rrrriiizz
    wrote on last edited by
    #1

    Hai everybody, Am using Vb.net as my frond end and sql server 2000 as my back end. in one of my screen am using grid control to view the data's in the tables, my problem is i want to filter the grid data's ie sno wise filter and name wise Filter. How can i do it? is it possible ? Please Give me detail description.:(

    M 1 Reply Last reply
    0
    • R rrrriiizz

      Hai everybody, Am using Vb.net as my frond end and sql server 2000 as my back end. in one of my screen am using grid control to view the data's in the tables, my problem is i want to filter the grid data's ie sno wise filter and name wise Filter. How can i do it? is it possible ? Please Give me detail description.:(

      M Offline
      M Offline
      Marcus J Smith
      wrote on last edited by
      #2

      Do you want a filter from user input or filter the data before it gets to the page? If you are wanting to pre-filter it then I would do that with your stored procedure. If you are looking to do this based on user input then you can set you dataset/datatable = to a dataview. Then use a Dataview.Filter = "Column = Validated user input" which is similar to SQL but only requires the WHERE (which is what the "=" means) so remember to use ' ' for characters and the exact value for numerics. Cleako

      R 1 Reply Last reply
      0
      • M Marcus J Smith

        Do you want a filter from user input or filter the data before it gets to the page? If you are wanting to pre-filter it then I would do that with your stored procedure. If you are looking to do this based on user input then you can set you dataset/datatable = to a dataview. Then use a Dataview.Filter = "Column = Validated user input" which is similar to SQL but only requires the WHERE (which is what the "=" means) so remember to use ' ' for characters and the exact value for numerics. Cleako

        R Offline
        R Offline
        rrrriiizz
        wrote on last edited by
        #3

        Thanks Mr.Cleako I want to filter the data's by user input in text box and then he press a button. ie am filtering employee database in that database it contains more than 600 records inthat you want to extract particular employee from that database in that case only am in need of grid filter option. in my form i used 5 controls 3 buttons and a textbox and a grid, user given his input in a text box and then press any one button ie filterby empno or filterby ename or by department in that case am using below code for on of my button press but it was not working tell me some suggestion or code Private Sub btneno_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneno.Click con.Open() str = "select * from empmaster1 where Eno='" & txtsearch.Text & "'" da = New OdbcDataAdapter(str, con) da.Fill(Dspay, "empmaster1") dgv.DataSource = Dspay con.Close() End Sub Grid name is dgv Dataset name is Dspay table name is empmaster1 in pageload event am writing code for connection Please help me.....

        M 1 Reply Last reply
        0
        • R rrrriiizz

          Thanks Mr.Cleako I want to filter the data's by user input in text box and then he press a button. ie am filtering employee database in that database it contains more than 600 records inthat you want to extract particular employee from that database in that case only am in need of grid filter option. in my form i used 5 controls 3 buttons and a textbox and a grid, user given his input in a text box and then press any one button ie filterby empno or filterby ename or by department in that case am using below code for on of my button press but it was not working tell me some suggestion or code Private Sub btneno_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneno.Click con.Open() str = "select * from empmaster1 where Eno='" & txtsearch.Text & "'" da = New OdbcDataAdapter(str, con) da.Fill(Dspay, "empmaster1") dgv.DataSource = Dspay con.Close() End Sub Grid name is dgv Dataset name is Dspay table name is empmaster1 in pageload event am writing code for connection Please help me.....

          M Offline
          M Offline
          Marcus J Smith
          wrote on last edited by
          #4

          rrrriiizz wrote:

          Private Sub btneno_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneno.Click con.Open() str = "select * from empmaster1 where Eno='" & txtsearch.Text & "'" da = New OdbcDataAdapter(str, con) da.Fill(Dspay, "empmaster1") dgv.DataSource = Dspay con.Close() End Sub

          If you are allowing them to type anything in the textbox then you should change your SQL to be "LIKE %'" & txtsearch.Text & "'%" instead. I would also suggest you not directly use the textbox text but set it to a variable and pre-validate what they typed because this can lead to a SQL Injection Attack by them typing in the correct commands.


          Cleako

          R 1 Reply Last reply
          0
          • M Marcus J Smith

            rrrriiizz wrote:

            Private Sub btneno_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneno.Click con.Open() str = "select * from empmaster1 where Eno='" & txtsearch.Text & "'" da = New OdbcDataAdapter(str, con) da.Fill(Dspay, "empmaster1") dgv.DataSource = Dspay con.Close() End Sub

            If you are allowing them to type anything in the textbox then you should change your SQL to be "LIKE %'" & txtsearch.Text & "'%" instead. I would also suggest you not directly use the textbox text but set it to a variable and pre-validate what they typed because this can lead to a SQL Injection Attack by them typing in the correct commands.


            Cleako

            R Offline
            R Offline
            rrrriiizz
            wrote on last edited by
            #5

            Mr.clicko This command also not working Please help me is my code is right? am n a great trouble with this filtering for past one week....

            M 1 Reply Last reply
            0
            • R rrrriiizz

              Mr.clicko This command also not working Please help me is my code is right? am n a great trouble with this filtering for past one week....

              M Offline
              M Offline
              Marcus J Smith
              wrote on last edited by
              #6

              The "LIKE" does not work either? Have you tried typing something in that you know for sure is present?

              Private Sub btneno_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneno.Click
              con.Open()
              str = "select * from empmaster1 where Eno='" & txtsearch.Text & "'"
              da = New OdbcDataAdapter(str, con)
              da.Fill(Dspay, "empmaster1")
              dgv.DataSource = Dspay
              con.Close()
              End Sub

              One thing that I would suggest is to convert the Eno column to a varchar if it is currently a numeric column. I do not know if that is your DB setup or not but it's worth a try. Select * FROM EmpMaster1 WHERE CAST(Eno AS VarChar(30)) LIKE %'" & txtSearch.Text & "'%"


              Cleako

              R 1 Reply Last reply
              0
              • M Marcus J Smith

                The "LIKE" does not work either? Have you tried typing something in that you know for sure is present?

                Private Sub btneno_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneno.Click
                con.Open()
                str = "select * from empmaster1 where Eno='" & txtsearch.Text & "'"
                da = New OdbcDataAdapter(str, con)
                da.Fill(Dspay, "empmaster1")
                dgv.DataSource = Dspay
                con.Close()
                End Sub

                One thing that I would suggest is to convert the Eno column to a varchar if it is currently a numeric column. I do not know if that is your DB setup or not but it's worth a try. Select * FROM EmpMaster1 WHERE CAST(Eno AS VarChar(30)) LIKE %'" & txtSearch.Text & "'%"


                Cleako

                R Offline
                R Offline
                rrrriiizz
                wrote on last edited by
                #7

                Mr.Cleako, this is also not working cause am trying to get the values for Particular Employee name also. but it is also not working. thanks for your supports and help for past four days am not able to browse. thats what Late reply. if there is any other Method or technique is there for filtering please tell me and also code or syntax. Please Help..... Thank You

                M 1 Reply Last reply
                0
                • R rrrriiizz

                  Mr.Cleako, this is also not working cause am trying to get the values for Particular Employee name also. but it is also not working. thanks for your supports and help for past four days am not able to browse. thats what Late reply. if there is any other Method or technique is there for filtering please tell me and also code or syntax. Please Help..... Thank You

                  M Offline
                  M Offline
                  Marcus J Smith
                  wrote on last edited by
                  #8

                  First just try opening Query Analyzer and try something like this but replace "value" with something real. Select * FROM EmpMaster1 WHERE EmployeeName LIKE '%value%' and if that works just translate it into something you can put into the code. Do the same for the number filter but you will probably need to do the cast to varchar in order for it to match if it is stored in the database as a number.


                  CleAkO

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups