By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,215 Members | 1,936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,215 IT Pros & Developers. It's quick & easy.

Adding textboxes for filtering in DataGrid header

P: n/a
Hi All,

- Visual Studio 2002

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.

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
If TextBoxFilter.Text <> "" Then
DataView1.RowFilter = e.SortExpression.ToString & " LIKE '" &
TextBoxFilter.Text & "*'"
End If
DataView1.Sort = e.SortExpression.ToString
DataGrid1.DataSource = DataView1
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!



Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.