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 Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.