Adding textboxes for filtering in DataGrid header

Discussion in 'ASP .Net Building Controls' started by Sam Vanderstraeten, Oct 1, 2003.

  1. 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
     
    Sam Vanderstraeten, Oct 1, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sam Vanderstraeten

    Adding textboxes for filtering in DataGrid header

    Sam Vanderstraeten, Oct 1, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    507
    Sam Vanderstraeten
    Oct 1, 2003
  2. Sam Vanderstraeten

    Adding textboxes for filtering in DataGrid header

    Sam Vanderstraeten, Oct 2, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    2,187
    Sam Vanderstraeten
    Oct 2, 2003
  3. Sam Vanderstraeten

    Adding textboxes for filtering in DataGrid header

    Sam Vanderstraeten, Oct 2, 2003, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    159
    Sam Vanderstraeten
    Oct 2, 2003
  4. Sam Vanderstraeten

    Adding textboxes for filtering in DataGrid header

    Sam Vanderstraeten, Oct 1, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    167
    Sam Vanderstraeten
    Oct 1, 2003
  5. Sam Vanderstraeten

    Adding textboxes for filtering in DataGrid header

    Sam Vanderstraeten, Oct 2, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    161
    Sam Vanderstraeten
    Oct 2, 2003
Loading...

Share This Page