Click here to Skip to main content
15,904,652 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,
I have delete button control in gridview when i press that button it will update the status of that row to deleted and change its background color to red. i have used following code in RowCommand event
protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e)
       {
           if (e.CommandName == "Delete")
               {
                  dgvJV.RowStyle.BackColor = Color.Red;
               }
       }


... but it changes the whole gridview to red .. so I guess I need to get row index.. How can I do that in RowCommand Event?

thanks in Advance
Posted
Updated 28-Mar-14 21:42pm
v2

Try this:

C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
      
            if (e.CommandName == "Delete")
            {
          

                GridViewRow selectedRow = (GridViewRow)((ImageButton)e.CommandSource).NamingContainer;
                int RowIndexx = Convert.ToInt32(selectedRow.RowIndex);

                GridView1.Rows[RowIndexx].BackColor = System.Drawing.Color.Blue;

           }
}
 
Share this answer
 
add command argument to delete button like below..

C#
CommandArgument='<%# Container.DataItemIndex%>' 


it will assign your row index to command argument.
Access this row index in row command event & try something like this..
C#
protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            if (e.CommandName == "Delete")
            {
                   int index = e.CommandArgument;
                   GridViewRow deletedRow= MyGridView.Rows[index];
                   deletedRow.BackColor= Color.Red;

            }
        }
 
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