Reputation: 140
protected void myOrdersListView_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if (e.CommandName == "removeBtn")
{
CabinTable.Rows.RemoveAt(Convert.ToInt32(e.Item.DataItemIndex));
CabinAdapter.Update(CabinTable);
Response.Redirect("Overview.aspx");
}
}
I have a database in Windows Azure and I want to delete a row after I click on a linkbutton in a listview. I have tried 100 different ways but I cant get it to work, please help me out!
How can I get the correct parameter in here? "CabinTable.Rows.RemoveAt(?)"
Upvotes: 0
Views: 68
Reputation: 8485
Instead of removing a row from the collection, delete the row itself:
CabinTable.Rows[Convert.ToInt32(e.Item.DataItemIndex)].Delete();
The sample also calls CabinTable.AcceptChanges();
after doing deletes, though I haven't tested to see if that is necessary in your case.
Upvotes: 1