Hi All,
- Visual Studio 2002
- VB.NET > ASP.NET
I created a DataGrid on a webform. This datagrid has sorting enabled.
I want to create in the header of each column (that is a sorting-hyperlink)
a textbox. When my user clicks on a sort-hyperlink, I want to sort that
column, but I also want to combine that with a rowfilter. That rowfilter
should be the filtervalue, entered in the textbox of that specific column.
F.e.:
Nr | Name | Age | Eyes |
===================
1 | John | 32 | blue |
-----------------------------
2 | Marco | 22 | brown |
-----------------------------
3 | Barry | 46 | blue |
-----------------------------
4 | Paolo | 19 | blue |
In the grid above, I would like to have a textbox in each columnheader... My
user enters f.e. *o* in the textbox of "Name", I want to attach a rowfilter
to this records. This will return me "John", "Marco" and "Paolo" (all
contain an "o"). When my user clicks on "Age", I want to sort those records
by their age. Now my user want to specify his filter, and wants to filter
those records by the color of their eyes. He enters "blue" in the textbox of
the column "Eyes", clicks on the sort-hyperlink and needs to get "John" and
"Paolo" (wich has an "o" AND has blue eyes).
This is my code to filter:
Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
DataGrid1.SortCommand
OleDbDataAdapter1.Fill(DataSet11)
If TextBoxFilter.Text <> "" Then
DataView1.RowFilter = e.SortExpression.ToString & " LIKE '" &
TextBoxFilter.Text & "*'"
End If
DataView1.Sort = e.SortExpression.ToString
DataGrid1.DataSource = DataView1
DataGrid1.DataBind()
End Sub
This code has only one textbox for each column, so I can filter only one
column at a time. Note that I can't create a textbox for each column
manually, because my Grid is generated dynamically at runtime.
Thanks for any suggestion!
Greetings,
Sam