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 6235733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:43:19+00:00 2026-05-24T10:43:19+00:00

I have a gridview that contains a column name History which has Plus (+)

  • 0

I have a gridview that contains a column name “History” which has Plus (+) image button. Clicking on the plus image button results in addition of new row beneath. Insertion of a new row should change the image of Plus image button to Minus (-) image button for that particular parent row only. Rest of the rows should have the Plus image button.

Q1. How to know the row index of the selected row, so that a image could be changed?

Secondly,If i click on Minus Image button, that should reset to Plus Image button and the added child row shouldn’t be seen.

Q2. How to change the image back to Plus Image button?

I have added the Plus image button in gridview template field. Hence when grid is being loaded, Plus image is visible.

Please advice!

Thanks!

  • 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-24T10:43:21+00:00Added an answer on May 24, 2026 at 10:43 am

    First of all add a template column with an image button in it:

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Srl"
        DataSourceID="EntityDataSource1" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/Left.gif" CommandName="Add" />
                </ItemTemplate>
            </asp:TemplateField>
            <%--Other columns--%>
        </Columns>
    </asp:GridView>
    

    Then in the GridView1_RowDataBound event handler set the button CommandArgument to row index:

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ImageButton button = (ImageButton)e.Row.FindControl("ImageButton1");
                button.CommandArgument = e.Row.RowIndex.ToString();
            }
        }
    

    Finally in GridView1_RowCommand event handler toggle ImageButton imageUrl and CommandName and do whatever you want do for adding and removing rows:

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow selectedRow = GridView1.Rows[index];
            ImageButton button = (ImageButton)e.CommandSource;
            switch (e.CommandName)
            {
                case "Add":
                    // Use selectedRow to add your rows       
                    button.ImageUrl = "~/images/down.gif";
                    button.CommandName = "Remove";
                    break;
                case "Remove":
                    // Use selectedRow to remove your rows
                    button.ImageUrl = "~/images/left.gif";
                    button.CommandName = "Add";
                    break;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that contains a GridView control which is databound to an
I have a gridview (gdvMyInfo) that contains q column of links I have grabbing
I have a column in a gridview that has a hyperlink defined in each
I have a GridView A that have many columns, one of those contains price
I have a GridView that allows editing the values in every column, in every
I have a gridview that I have added a checkbox column using a templatefield
I have an gridview that I am adding onclick events to a checkbox column
I currently have a gridview that has an asp:ButtonField as one of the columns.
I have a ASP.net gridview that I am trying bind to. My DataSource has
I have a GridView to which I bind a dataTable that I manually created.

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.