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

  • Home
  • SEARCH
  • 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 5838623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:29:16+00:00 2026-05-22T11:29:16+00:00

In my project, I have grid view which is not connected with database. It

  • 0

In my project, I have grid view which is not connected with database. It has data table as its source and rows are dynamically added on button click event of “AddNewRowBtn”. Each of these rows contain a button “Remove”. If user clicks on remove button in any of the row, then that row has to be deleted. For that I need row index of the row of which the button is clicked. How to get the row index of that row?

The code for my .aspx.cs page is as below.

using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class AppForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
   {
    if (!IsPostBack)
    {
        setInitialRow();
    } 
}
protected void addRowBtn_Click(object sender, EventArgs e)
{
    AddNewRow();
}
public void setInitialRow()
{
    DataTable Table = new DataTable();
    DataRow dr = null;
    Table.Columns.Add(new DataColumn("Qualification", typeof(string)));
    Table.Columns.Add(new DataColumn("QualiId", typeof(Int32)));
    Table.Columns.Add(new DataColumn("Percentage", typeof(float)));
    Table.Columns.Add(new DataColumn("PassingYear", typeof(Int32)));
    Table.Columns.Add(new DataColumn("InstituteName", typeof(string)));
    dr = Table.NewRow();

    dr["Percentage"] = DBNull.Value;
    dr["PassingYear"] = DBNull.Value;
    dr["InstituteName"] = string.Empty;

    Table.Rows.Add(dr);
    Session.Add("CurTable", Table);
    QualificationGrid.DataSource = Table;
    QualificationGrid.DataBind();


    //ArrayList Array = new ArrayList();
    //DataSet ds = new DataSet();
    DropDownList DDL = (DropDownList)QualificationGrid.Rows[0].Cells[0].FindControl("QualificationList");
    FillDropDownList(DDL);
}
public void AddNewRow()
{
    if (Session["CurTable"] != null)
    {
        DataTable CurTable = (DataTable)Session["CurTable"];
        DataRow CurRow = null;
        if (CurTable.Rows.Count > 0)
        {
            CurRow = CurTable.NewRow();
            CurTable.Rows.Add(CurRow);
            Session.Add("CurTable", CurTable);
            for (int count = 0; count < CurTable.Rows.Count - 1; count++)
            {
                DropDownList DDL = (DropDownList)QualificationGrid.Rows[count].Cells[0].FindControl("QualificationList");
                TextBox PercentageBox = (TextBox)QualificationGrid.Rows[count].Cells[1].FindControl("percentageBox");
                DropDownList YearList = (DropDownList)QualificationGrid.Rows[count].Cells[0].FindControl("yearList");
                TextBox InstituteNameBox = (TextBox)QualificationGrid.Rows[count].Cells[1].FindControl("InstituteNameBox");

                CurTable.Rows[count]["Percentage"] = PercentageBox.Text;
                CurTable.Rows[count]["PassingYear"] = YearList.SelectedItem.Text;
                CurTable.Rows[count]["InstituteName"] = InstituteNameBox.Text;
                CurTable.Rows[count]["Qualification"] = DDL.SelectedItem.Text;
                CurTable.Rows[count]["QualiId"] = DDL.SelectedValue;
            }
            QualificationGrid.DataSource = CurTable;
            QualificationGrid.DataBind();
        }
    }
    setPreviousData();
}
public void setPreviousData()
{
    int RowIndex = 0;
    if (Session["CurTable"] != null)
    {
        DataTable RestoreTable = (DataTable)Session["CurTable"];
        if (RestoreTable.Rows.Count > 0)
        {
            for (int row = 0; row < RestoreTable.Rows.Count; row++)
            {
                DropDownList DPList = (DropDownList)QualificationGrid.Rows[row].Cells[0].FindControl("QualificationList");
                TextBox PercentageBox = (TextBox)QualificationGrid.Rows[row].Cells[1].FindControl("percentageBox");
               // TextBox YearBox = (TextBox)QualificationGrid.Rows[row].Cells[2].FindControl("yearBox");
                DropDownList YearList = (DropDownList)QualificationGrid.Rows[row].Cells[0].FindControl("yearList");
                TextBox InstituteName = (TextBox)QualificationGrid.Rows[row].Cells[3].FindControl("InstituteNamebox");

                FillDropDownList(DPList);

                if (row < RestoreTable.Rows.Count - 1)
                {
                    PercentageBox.Text = RestoreTable.Rows[row]["Percentage"].ToString();
                    InstituteName.Text = RestoreTable.Rows[row]["InstituteName"].ToString();

                    DPList.ClearSelection();
                    DPList.Items.FindByText(RestoreTable.Rows[row]["Qualification"].ToString()).Selected = true;

                    YearList.ClearSelection();
                    YearList.Items.FindByText(RestoreTable.Rows[row]["PassingYear"].ToString()).Selected = true;
                }
                RowIndex++;
            }
        }
    }
}
private ArrayList FillArrayList()
{
    ArrayList ArrayList = new ArrayList();
    DataSet ds = new DataSet();
    using (DataOperation oDo = new DataOperation())
    {
        DataTable dt = oDo.DropDownList("select * from tblQualificationMaster");
        for (int count = 0; count < dt.Rows.Count; count++)
        {
            ArrayList.Add(new ListItem(dt.Rows[count][1].ToString(), dt.Rows[count][0].ToString()));
            //ArrayList.Add(new ListItem(ds.Tables[0].Rows[count][1].ToString(), ds.Tables[0].Rows[count][0].ToString()));
        }
    }
    return ArrayList;
}
private void FillDropDownList(DropDownList DDL)
{
    ArrayList ArrayList = FillArrayList();
    foreach (ListItem item in ArrayList)
    {
        DDL.Items.Add(item);
    }
    DDL.Items.Insert(0, "Select Year");
}

protected void removeBtn_Click(object sender, EventArgs e)
{
    int row = QualificationGrid.c
}

}

  • 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-22T11:29:16+00:00Added an answer on May 22, 2026 at 11:29 am

    Besides the possibilities listed in @Alison’s answer (using SelectedRow is definitely the simplest option, if it works for you), you can also go get the RowIndex of the actual row itself.

    In the event handler for the button click (where the sender is your Button, LinkButton, or ImageButton), use the following (example sender type ImageButton):

    (GridViewRow)(((ImageButton)sender).Parent.Parent)
    

    To get the row as a GridViewRow, and then use the GridViewRow.RowIndex property.

    EDIT: I’m not sure how the third option in @Alison’s link works compared to this one – this one uses sender.Parent.Parent to get the actual table row, whereas that one uses the NamingContainer. I’d say if your GridView has been manually altered at all (rows being added/removed from the table itself) you could run into issues using the NamingContainer.

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

Sidebar

Related Questions

ok i have a project which has many gridview in its pages... now i
In my project I have an Xceed data grid which is bound to a
I have a grid view utilizing sql data source. Now I want to delete
I have a very simple web part. I have a single grid view, which
I have a GridView which retrieves data from a database. Users have roles, some
In my View, which is a UserControl I have a ListView which has a
I have a grid in a XAML file in a WPF project. This MainGrid
I have a table of information in a SQL Server database and another table
I have created a Conceptual Model in my project using a table in my
I have project on recruitment.In this project, at one form I have a grid

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.