AvinashKN
asked on
Deleting Gridview Row
Hello all,
I would like to know how to delete a gridview row on button click. I' m not using the auto generated delete button because of a requirement.
Thanks for the help.
I would like to know how to delete a gridview row on button click. I' m not using the auto generated delete button because of a requirement.
Thanks for the help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oops forgot to add that 'You have to re-bind the grid after you delete the record in order to reflect the changes in web form'
ASKER
Thanks for the quick reply.
I have created a method to remove the row. What I'm finding difficult is to get the value of the row.
For example...
I'm using the following code to change the color of a particular account number..
if (e.Row.RowType == DataControlRowType.DataRow )
{
string strAccountNumber = Convert.ToString(DataBinde r.Eval(e.R ow.DataIte m, "Account No"));
if (strAccountNumber == "7000512518001")
e.Row.BackColor = System.Drawing.Color.Red;
}
I would like to know how to select the row based on the account number like I'm doing there.
I have created a method to remove the row. What I'm finding difficult is to get the value of the row.
For example...
I'm using the following code to change the color of a particular account number..
if (e.Row.RowType == DataControlRowType.DataRow
{
string strAccountNumber = Convert.ToString(DataBinde
if (strAccountNumber == "7000512518001")
e.Row.BackColor = System.Drawing.Color.Red;
}
I would like to know how to select the row based on the account number like I'm doing there.
Hi, like I said, in the row, you have to set your button's command argument to container.dataitemindex. Set your "Account No" as datakey value for your gridview, you can even set it from the front end property box.
Then access current row's datakey value to get your account no as I have already mentioned in the example.
Then access current row's datakey value to get your account no as I have already mentioned in the example.