Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7414947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:12:08+00:00 2026-05-29T07:12:08+00:00

I add a ButtonField in one Gridview’s Column so there is Buttonfield for each

  • 0

I add a ButtonField in one Gridview’s Column so there is Buttonfield for each Record as below code

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

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

I add a column STATUS in the Gridview…

I wants to change the image of Buttonfield 4 times..

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”..

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

My code is as below..

protected void GvDetail_RowCommand(object sender, GridViewCommandEventArgs e)
{

if (e.CommandName==”ggg”)
{

        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();


    }


}

How can i do it?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:12:10+00:00Added an answer on May 29, 2026 at 7:12 am

    you should add command :

    enter image description here

    bind data

    enter image description here

    write code for command

    https://i.stack.imgur.com/c1j0Q.png
    enter image description here

    press

    enter image description here

    enter image description here

    P.S. you could have used findcontrol

    but since your gridview is not within a template –

    so it doesn’t have an Id

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I add asp.net file upload control as follows: <asp:FileUpload ID=filesFileUpload runat=server /> <asp:RegularExpressionValidator ID=RegularExpressionValidator3
I have a asp gridview with button field column on that button click I
I add many check boxes to the excel sheet programaticaly using the following code:
I am creating a gridview dynamically with a ButtonField and several BoundFields. ButtonField button
add({ title: args.node.id, iconCls: 'tabs', items: [{html: '<code class=prettyprint><?php\necho \'Hello World!\';</code>', width: '100%', hieght:
I have a gridView binded to a data source, and I have a ButtonField
I made a popup screen in which there is an EditField, and two ButtonField
The below code generates a buttons within a loop and attempts to pass a
I have record from sql database printing into gridview. I want to make another
Hallo there I have and imageField as part of a gridview and would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.