Access GridView DataKeys on Delete

R

Richard Coltrane

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top