Easy way to clear the DataGrid

Discussion in 'ASP .Net Datagrid Control' started by Janaka, Sep 17, 2004.

  1. Janaka

    Janaka Guest

    Is there a function to clear the Items out of the DataGrid or DataList? In
    my page I want the user to be able to do different searches and before
    rebinding the DataGrid, specify how many rows to display. Currently I am
    hiding the grid by specifying Visible = false. However this still persits
    all the Items in the viewstate. I do need viewstate when its bound though.
    I was thinking it would be cleaner to delete the items from the Grid - is
    this possible?
     
    Janaka, Sep 17, 2004
    #1
    1. Advertising

  2. Have you tried just clearing the data source and rebinding the control?


    DataGrid1.DataSource = Nothing
    DataGrid1.Databind()

    Hope that helps,

    Joel Cade, MCSD .Net, MCAD, MCP
    Fig Tree Solutions, LLC
    http://www.figtreesolutions.com

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Joel Cade, MCSD, Sep 17, 2004
    #2
    1. Advertising

  3. Janaka

    Gary K Guest

    I agree with Joel, in that I think that's part of what you need to do to
    'clear' the grid. Have you tried limiting you're SQL results to the number
    you want, all you need to add to the SELECT statement is add TOP x [PERCENT],
    like so:

    SELECT TOP 20 col1, col2 FROM table1; { returns the first 20 }
    SELECT TOP 10 PERCENT col1, col2 FROM table1 ORDER BY col1; { returns the
    first 10% of entries (ie, first 10 of 100) }

    NOTE that due to it returning the FIRST entries, the ORDER BY clause becomes
    very important.

    "Joel Cade" <Joel Cade>, "MCSD" wrote:

    > Have you tried just clearing the data source and rebinding the control?
    >
    >
    > DataGrid1.DataSource = Nothing
    > DataGrid1.Databind()
    >
    > Hope that helps,
    >
    > Joel Cade, MCSD .Net, MCAD, MCP
    > Fig Tree Solutions, LLC
    > http://www.figtreesolutions.com
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    >
     
    Gary K, Sep 23, 2004
    #3
    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. Hazzard
    Replies:
    2
    Views:
    651
    Hazzard
    Apr 6, 2004
  2. Martin Marinov
    Replies:
    2
    Views:
    5,525
  3. Bruno Desthuilliers
    Replies:
    5
    Views:
    395
    Bruno Desthuilliers
    Aug 29, 2007
  4. David

    Response.Clear() doesn't clear

    David, Jan 31, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    1,038
    Mark Fitzpatrick
    Jan 31, 2008
  5. InvalidLastName

    Unrecognized element 'add' after <clear></clear>

    InvalidLastName, Feb 26, 2007, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    971
    Steven Cheng[MSFT]
    Mar 6, 2007
Loading...

Share This Page