Click here to Skip to main content
15,615,787 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a button in the first column of the datagridview. Whenever I click on the button in the datagridview, i want to delete that row plz give an idea

1 solution

set the command name of that button to "Delete" and then check the command name in the datagrid's rowcommand property and perform delete operation and bindgrid operation there so the grid after deleting that record will be updated...

also dont forget to make the id property as a datakey so you can pass it in command argument and delete the row you wish to.

for eg..

protected void datagrid_RowCommand(object sender, GridViewCommandEventArgs e)
               if (e.CommandName == "Delete")
                   int Args = Convert.ToInt32(e.CommandArgument);
                   string _id = grddisplayrequest.DataKeys[Args]["ID"].ToString();

/* Perform Delete operation here */
/* bind grid operation here */
           catch (Exception ex)

I hope this helped you.

Please give vote if this answer helped you. :)
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900