简体   繁体   中英

How to get row index of a gridview when autogenerated delete column button is fired?

I have a gridview which has both autoGenerated delete as well as AutoGenerated select buttons. I can get the current row of select button by gridView1.SelectedIndex but I can't get the same for the delete button. how to get it?

You should be able to get it by using the gridviews rowDeleting event

void CustomersGridView_RowDeleting
    (Object sender, GridViewDeleteEventArgs e)
{
    TableCell cell = CustomersGridView.Rows[e.RowIndex].Cells[2];
    if (cell.Text == "Beaver")
    {
        e.Cancel = true;
        Message.Text = "You cannot delete customer Beaver.";
    }
    else
    {
        Message.Text = "";
    }
}  

Note: This code was copied from, http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdeleting%28v=vs.110%29.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM