Change the Image(image url) of ButtonField which is added in Gridview by onclick event
<p>I add a ButtonField in one Gridview's Column so there is Buttonfield for each Record as below code</p>

<pre><code>&lt;asp:GridView ID="GvDetail" runat="server"&gt;
    &lt;Columns&gt;
        &lt;asp:ButtonField ButtonType="Image" ImageUrl="~/Img/Black.png" CommandName="ggg" /&gt;
    &lt;/Columns&gt;
&lt;/asp:GridView&gt;
</code></pre>

<p>In this i wants to change the image(image url) by clicking on that Button field..</p>

<p><strong>I add a column STATUS in the Gridview...</strong></p>

<p>I wants to change the image of Buttonfield 4 times..</p>

<p>it means default it displays the "black image" and STATUS is "1" 
on 1st click it changes to "blue image" and STATUS must be changed to "2" 
on 2nd click it changes to "green image" STATUS "3"
 on 3rd click it changes to "red image" STATUS "4". 
and on 4th click again it changes to "black image" STATUS "1"..</p>

<p>Its also working like on 1st click it change the image from black to blue and STATUS from "1" to "2" 
but when again i click on that it does not work.. to change it again. it needs to stop the project from running. and rerun it. then it works for only one click then again needs to stop the project and so on... 
Any Solution for this????</p>

<p>My code is as below..</p>

<p>protected void GvDetail_RowCommand(object sender, GridViewCommandEventArgs e)
    {</p>

<p>if (e.CommandName=="ggg")
        {</p>

<pre><code>        int index = Convert.ToInt32(e.CommandArgument);

        int temp;
        temp = Convert.ToInt32(GvDetail.Rows[index].Cells[1].Text);
      // gets the ID of clicked row from First Column(Name="Id")

        com = new SqlCommand();
        var _with1 = com;
        _with1.Connection = con;


        if (GvDetail.Rows[index].Cells[3].Text == "1")
        {
            string str1;
            str1 = "update SubTask set Status='2' where ID= '" + temp + "'";
            _with1.CommandText = str1;
            Label4.Text = "Start";
            Label4.Text = str1;

            GridViewRow gvRow = GvDetail.Rows[index];
            ((ImageButton)gvRow.Controls[0].Controls[0]).ImageUrl = "~/Image/Green.png";
        }

        else if (GvDetail.Rows[index].Cells[3].Text == "2")
        {
            string str1;
            str1 = "update SubTask set Status='3' where ID= '" + temp + "'";
            _with1.CommandText = str1;
            Label4.Text = "Start";
            Label4.Text = str1;
            GridViewRow gvRow = GvDetail.Rows[index];
            ((ImageButton)gvRow.Controls[0].Controls[0]).ImageUrl = "~/Image/Blue.png";
        }

        else if (GvDetail.Rows[index].Cells[3].Text == "3")
        {
            string str1;
            str1 = "update SubTask set Status='4' where ID= '" + temp + "'";
            _with1.CommandText = str1;
            Label4.Text = "Start";
            Label4.Text = str1;
            GridViewRow gvRow = GvDetail.Rows[index];
            ((ImageButton)gvRow.Controls[0].Controls[0]).ImageUrl = "~/Image/Red.png";
        }

        else if (GvDetail.Rows[index].Cells[3].Text == "4")
        {
            string str1;
            str1 = "update SubTask set Status='1' where ID= '" + temp + "'";
            _with1.CommandText = str1;
            Label4.Text = "Start";
            Label4.Text = str1;
            GridViewRow gvRow = GvDetail.Rows[index];
            ((ImageButton)gvRow.Controls[0].Controls[0]).ImageUrl = "~/Image/Black.png";
        }

        _with1.ExecuteNonQuery();


    }


}
</code></pre>

<p>How can i do it?</p>

<p>Thanks in advance</p>
