python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
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

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions