Finding rows after a filter has been applied

Last post 02-02-2009 2:32 AM by Qin Dian Tang - MSFT. 3 replies.

Sort Posts:

  • Finding rows after a filter has been applied

    01-28-2009, 3:50 AM
    • Member
      36 point Member
    • sp4ceman
    • Member since 11-03-2005, 8:13 AM
    • Posts 28

    I have a gridview bound to an objectDataSource.
    It is set to filter on one or two fields, this is all working fine.

    Is there a way to programatically access the rows that are displayed after a filter has been applied?

    please don't read this if you do i will disappea....
  • Re: Finding rows after a filter has been applied

    02-02-2009, 1:02 AM

    Hi sp4ceman,

    You can loop through the GridView, whenever it has been applied or not. You can access all rows that are being displayed in GridView:

    foreach (GridViewRow gvr in GridView1.Rows)
    {
        Response.Write("This is no." + (gvr.RowIndex + 1).ToString() + " Row");
        //string data = gvr.Cells[0].Text;
    }

    Thanks,

    Qin Dian Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Finding rows after a filter has been applied

    02-02-2009, 2:21 AM
    • Member
      36 point Member
    • sp4ceman
    • Member since 11-03-2005, 8:13 AM
    • Posts 28
    I have a grid bound to a datasource containing say 8 rows. I apply a filter leaving only 3 rows visible, the other 5 are filtered out.

    If I loop through the rowCollection it loops through all 8 rows, not only the visible 3. I need to only access the 3 visible rows..

    The rowDataBound event fires 3 times, once for each of the rows returned... so I made my changes there...
    Whats weird is that even though the rowDataBound event fires 3 times, the rows.Count remains at 8..

    I thought there would be a filteredRows property or something on a grid to allow me to access only the 3 returned rows..
    please don't read this if you do i will disappea....
  • Re: Finding rows after a filter has been applied

    02-02-2009, 2:32 AM

    Hi sp4ceman,

    Do you set visible=false in rows or filter the data source of GridView to filter out the rows. Show me your GridView and the code for filtering and RowDataBound.

    Thanks,

    Qin Dian Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (4 items)