How to delete Rows of a GridView?

Discussion in 'ASP .Net' started by Astrith, Sep 26, 2008.

  1. Astrith

    Astrith Guest

    I am a Newbie and i am scratching my head over how to delete a Row from a
    GridView.

    I have this GridView which has 3 fields called ID,ProjCode and
    ProjDescription of which ID is the hidden field. I have also set the property
    AutoGenerateDeleteButton="True".

    Now as i understand, i have to write code in the GridView1_RowDataBound and
    GridView1_RowDeleting METHODS to perform deletion of row. I have been
    searching for long for the code but no luck.

    Can sombody help me in deleting the rows of my Gridview?
     
    Astrith, Sep 26, 2008
    #1
    1. Advertising

  2. Astrith

    Lanoli

    Joined:
    Sep 26, 2008
    Messages:
    2
    In the delete handler :
    Code:
    Private Sub DataGridEigendom_r_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles DataGridEigendom_r.RowDeleting
    remove the data you want to have removed from the source you are binding to the gridview and rebind.
     
    Lanoli, Sep 26, 2008
    #2
    1. Advertising

  3. Astrith

    Guest

    hi
    it is so clear , you must push the delete buttton ... :)
    you should delete that record from your db
    gridview just is a control that show your records
    i think you don't have any Primary Key in your Table
     
    , Sep 26, 2008
    #3
  4. Astrith

    Bogdan Guest

    "Astrith" <> wrote in message
    news:...
    >I am a Newbie and i am scratching my head over how to delete a Row from a
    > GridView.
    >
    > I have this GridView which has 3 fields called ID,ProjCode and
    > ProjDescription of which ID is the hidden field. I have also set the
    > property
    > AutoGenerateDeleteButton="True".
    >
    > Now as i understand, i have to write code in the GridView1_RowDataBound
    > and
    > GridView1_RowDeleting METHODS to perform deletion of row. I have been
    > searching for long for the code but no luck.
    >
    > Can sombody help me in deleting the rows of my Gridview?
    >


    Generally, deleting a row from your data source will also delete a
    corresponding row from your gridview, provided that the data source is bound
    to the gridview afterwards.

    Binding could be 'automatic' if you have a Delete button (as you mentioned
    above) and have a data source with a DeleteMethod defined in your aspx and
    referenced by the gridview .

    If your data source is not defined/referenced as stated above then you need
    to do the deletion and rebinding 'manually' in RowDeleting event handler.

    RowDataBound handler is not needed although it is quite often used to attach
    a client script to the delete button so a user is prompted to confirm the
    deletion.

    Bogdan
     
    Bogdan, Sep 26, 2008
    #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. MC
    Replies:
    2
    Views:
    8,296
  2. Michael
    Replies:
    2
    Views:
    1,545
    Michael
    Apr 30, 2008
  3. Andy B
    Replies:
    0
    Views:
    447
    Andy B
    Aug 8, 2008
  4. VijayRama
    Replies:
    2
    Views:
    2,355
    Gregory A. Beamer
    Oct 12, 2009
  5. PetroTiburcio

    Delete rows in Gridview

    PetroTiburcio, Jun 3, 2013, in forum: C Programming
    Replies:
    0
    Views:
    308
    PetroTiburcio
    Jun 3, 2013
Loading...

Share This Page