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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:29:52+00:00 2026-06-17T09:29:52+00:00

I have Gridview with some records (1 record=1 row). On every row I added

  • 0

I have Gridview with some records (1 record=1 row).

On every row I added a button to delete this record from my mysql db.

Every row has the same button.

The problem is I need to know in which row the button was clicked? I need this to get a row index to get id of my record which is in that row.

How can I do this in easiest way?

Gridview:

        <asp:GridView ID="GridView1" runat="server" 
        CellPadding="6" EnableModelValidation="True" ForeColor="#333333" 
        GridLines="None" Caption="TWOJE WIZYTY" Font-Bold="True" 
        onrowcreated="GridView1_RowCreated" style="text-align: left">
        <AlternatingRowStyle BackColor="#AEAEAE" />
        <EditRowStyle BackColor="Blue" />
        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#868686" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="Blue" ForeColor="#333333" HorizontalAlign="Center" />
        <RowStyle BackColor="#C7C7C7" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
    </asp:GridView>

The button is being added like that:

        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        Button b1 = new Button();
        b1.Text = "usuń";
        b1.OnClientClick = "return potwierdzenie()";
        b1.Click+=new EventHandler(b1_Click);
        TableCell cel = new TableCell();
        cel.Width = Unit.Pixel(180);
        if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.Cells[0].Visible = false;
            e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Right;
            e.Row.Cells[2].Text = "";
            e.Row.Cells.Add(cel);
        }
        else
        {
            //HERE IS MY BUTTON ADDED! *********************
            cel.Controls.Add(b1);
            cel.HorizontalAlign = HorizontalAlign.Right;
            e.Row.Cells[0].Visible = false;
            e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Right;
            e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Left;
            e.Row.Cells.Add(cel);
        }
    }
  • 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-06-17T09:29:53+00:00Added an answer on June 17, 2026 at 9:29 am

    You can use the NamingContainer property of your button to get the GridViewRow. Then you have all you need to find your other controls (f.e. the control with ID if you use TemplateFields).

    protected void button_Delete_click(Object sender, EventArgs e)
    {
        Button btn = (Button) sender;
        GridViewRow row = (GridViewRow) btn.NamingContainer;
        // assuming you store the ID in a Hiddenield:
        Hiddenield hiddenID = (HiddenField) row.FindControl("HiddenID");
        int ID = int.Parse(hiddenID.Value);
        // delete the record
    }
    

    You can also get the row-index via row.RowIndex.

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

Sidebar

Related Questions

Need some help to solve this. I have a gridview and inside the gridview
I have a GridView containing records from a table which can be deleted or
I have some methods in my BLL that fetch some records from database and
I have a page that contains a Gridview showing a record from a db
I have a DataRepeater with a GridView inside to display some tables from a
I have a GridView with some data from my database. However, when hovering the
Here i have gridview which contain some values retrieved from database.We put radiobutton list
I have a gridview and I add some buttons programmatically to this grid. I
I have a gridview that shows records from a database table. Now, I want
So I have some GridView. When you edit a row, a particular column changes

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.