Grid Filtering
-
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.:(
-
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.:(
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 -
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. CleakoThanks 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.....
-
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.....
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
-
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
-
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....
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 SubOne 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
-
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 SubOne 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
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
-
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
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