Access GridView DataKeys on Delete

Discussion in 'ASP .Net' started by Richard Coltrane, Dec 12, 2007.

  1. Hi There,

    In binding my gridview i do this:

    private void BindGrid(int month, int year)
    {
    BookingProvider provider = new BookingProvider();
    DataTable dt = provider.GetMonthsEvent(month, year);
    this.gridBookings.DataSource = dt;
    this.gridBookings.DataKeyNames = new string[] { "Id" };
    this.gridBookings.DataBind();
    }

    And when deleting a row after a delete command I do this

    protected void gridBookings_RowDeleting(object sender,
    GridViewDeleteEventArgs e)
    {
    BookingProvider provider = new BookingProvider();
    provider.DeleteBooking((long)(e.Keys["Id"]));
    }

    How come it fails??? The keys collection is null?
    Also e.RowIndex = the key of the row being deleted as per the database??
    i.e. RowIndex = Key??
    But the docs read like e.RowIndex is supposed to be the index of the row
    according to the grid. i.e a grid with 6 rows I would have though the 6 th
    row would have a row index of 5 (zero based)???

    Thanks
    Richard Coltrane, Dec 12, 2007
    #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. =?Utf-8?B?TGluZ28=?=

    Gridview asp.net 2.0 datakeys not loading

    =?Utf-8?B?TGluZ28=?=, Oct 31, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    591
    =?Utf-8?B?TGluZ28=?=
    Oct 31, 2005
  2. Narshe
    Replies:
    2
    Views:
    1,021
    Narshe
    Jun 29, 2006
  3. Guest
    Replies:
    2
    Views:
    5,539
    wwwtar
    Nov 2, 2006
  4. =?Utf-8?B?R3JlZw==?=

    GridView DataKeys problem

    =?Utf-8?B?R3JlZw==?=, Oct 30, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    683
    Davior
    Dec 13, 2006
  5. =?Utf-8?B?UmljayBEcm9za2U=?=

    Gridview DataKeys property not set when PageIndexChanged fires

    =?Utf-8?B?UmljayBEcm9za2U=?=, Dec 13, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    380
    =?Utf-8?B?UmljayBEcm9za2U=?=
    Dec 13, 2006
Loading...

Share This Page