Reset DataGrid

Discussion in 'ASP .Net Datagrid Control' started by Tom McLaughlin, Apr 22, 2004.

  1. I have a datagrid on a form that I populate
    with the following:

    DS.Clear()
    DA.Fill(DS,myTable)

    DataGrid1.DataSource = DS
    DataGrid1.Datamember = myTable

    That works fine but when I try to reload
    the same datagrid with a different DataSet
    the original data is still there. All that happens
    it seems is that the added columns are appended
    and not replaced.

    What can I do to reset the datagrid to enable it
    to receive all new information?

    Tom
    Tom McLaughlin, Apr 22, 2004
    #1
    1. Advertising

  2. Tom McLaughlin

    Juliet Choy Guest

    It is strange, in which stage of the page (Page_Load, Page_Init?) did
    you bind your DataGrid? Or did you make sure that it only bind itself
    when it is not post back?

    Anyway, if problem still persist, you may clear your datagrid before
    databind by:

    DataGrid1.Items.Clear();

    Though it is quite rare that you need to do this.

    Regards,
    Juliet Choy
    Hong Kong
    Microsoft MVP - ASP.NET

    Tom McLaughlin wrote:

    > I have a datagrid on a form that I populate
    > with the following:
    >
    > DS.Clear()
    > DA.Fill(DS,myTable)
    >
    > DataGrid1.DataSource = DS
    > DataGrid1.Datamember = myTable
    >
    > That works fine but when I try to reload
    > the same datagrid with a different DataSet
    > the original data is still there. All that happens
    > it seems is that the added columns are appended
    > and not replaced.
    >
    > What can I do to reset the datagrid to enable it
    > to receive all new information?
    >
    > Tom
    >
    >
    >
    Juliet Choy, Apr 23, 2004
    #2
    1. Advertising

  3. Juliet, Thanks for your replay.

    I'm new to VB.net and I am using this example
    from one of Microsoft press books. So I am
    not sure what is meant by (Page_Load, Page_Init?).
    The example does not use either one so I tried
    DataGrid1.Items.Clear() which also failed.
    The syntax did not like "Items" so I changed it
    to "Item" now I receive the following:
    "Overload resolution failed because no accessible 'Item'
    accepts this number of arguments.'

    I am self taught in Visual Basic 5 and found it quit easy.
    But this VB.net is a killer. I am not sure where to
    go from here.

    Tom
    Tom McLaughlin, Apr 24, 2004
    #3
  4. Hi Tom,

    ASP.NET uses an event-driven model, this Page_Load, Page_Init etc. are
    the event handler which would run during different stages of ASP.NET
    execution. For databinding a DataGrid, normally you should put the codes
    in the Page_Load event handler.

    If you just start learning VB.NET and ASP.NET, I would highly recommend
    you first go through the QuickStart tutorials provided by the framework.
    You can go to the official site of ASP.NET: http://www.asp.net and click
    on the "Tutorials" tab, then you can access the quickstart tutorials.

    For books, the most recognized good book on ASP.NET should be Walther's
    ASP.NET Unleashed published by SAMS. Be sure to buy one from your
    bookstore if you are going to learn ASP.NET seriously.

    Hope my advices can help you.

    Best Regards,
    Juliet Choy
    Hong Kong
    Microsoft MVP - ASP.NET

    Tom McLaughlin wrote:
    > Juliet, Thanks for your replay.
    >
    > I'm new to VB.net and I am using this example
    > from one of Microsoft press books. So I am
    > not sure what is meant by (Page_Load, Page_Init?).
    > The example does not use either one so I tried
    > DataGrid1.Items.Clear() which also failed.
    > The syntax did not like "Items" so I changed it
    > to "Item" now I receive the following:
    > "Overload resolution failed because no accessible 'Item'
    > accepts this number of arguments.'
    >
    > I am self taught in Visual Basic 5 and found it quit easy.
    > But this VB.net is a killer. I am not sure where to
    > go from here.
    >
    > Tom
    >
    >
    Juliet Choy [MVP], Apr 26, 2004
    #4
    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. Martin Bammer
    Replies:
    0
    Views:
    612
    Martin Bammer
    Nov 17, 2003
  2. Curt_C [MVP]

    How to reset DataGrid to view DB updates

    Curt_C [MVP], Feb 17, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    1,641
  3. Lee Price

    Reset datagrid

    Lee Price, Jul 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,964
  4. Andreas Klemt
    Replies:
    0
    Views:
    292
    Andreas Klemt
    Oct 8, 2003
  5. Josh Behl
    Replies:
    3
    Views:
    120
    Imtiaz Hussain
    Oct 29, 2003
Loading...

Share This Page