Adding textboxes for filtering in DataGrid header

  • Thread starter Sam Vanderstraeten
  • Start date
S

Sam Vanderstraeten

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.DataGridSortCommandEventArgs) 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top