row index in gridview in c#- Gridview Row index at Runtime

row index in gridview in c#- Gridview Row index at Runtime

Hello everyone,

I'm going to share the code-sample of row index in gridview in c# .net using on click of link-button and image button.

Table of Contents

1. On click link button find gridview row index in C#.
2. On click Image button find gridview row index in C#.

Note: Image is a Temple field item, we create a click and then generate the events of on row and get the index. Using the line of code


[ int index = (((LinkButton)sender).Parent.Parent as GridViewRow).RowIndex; ]

and then get the Cell values with using index. i.e.


[ string strFilePath = GridViewId.Rows[index].Cells[1].Text; ]

For more details you can seen the below example.


1. Row index in gridview (On click link button)


protected void lkbVideo_Click(object sender, EventArgs e)
{
    int index = (((LinkButton)sender).Parent.Parent as GridViewRow).RowIndex;
    string strFilePath = GridViewId.Rows[index].Cells[1].Text;
}
                                                                

2. Row index in gridview (On click Image button)

protected void ImgbuttonVideo_Click(object sender, EventArgs e)
{
    int index = (((ImageButton)sender).Parent.Parent as GridViewRow).RowIndex;
    string strFilePath = GridView1.Rows[index].Cells[2].Text;
}


The above code is use to find the row index of the grid view, when you click to Insert Update Edit and Delete on the gridview row image button/ link button etc.

ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

row index in gridview in c#- Gridview Row index at Runtime  row index in gridview in c#- Gridview Row index at Runtime Reviewed by Unknown on 12:17 AM Rating: (5)
www.code-sample.com/. Powered by Blogger.
^