Hi, you can solve this with this code:
something along these lines
I assumed that you have a button in each row of the grid, and you want to find out in which row you clicked the button, and get the value of another specific cell in the same row that this button is associated with:
protected void Downloadbtn_Click(object sender, EventArgs e) { Button clickedButton = sender as Button; GridViewRow clickedGridViewRow = (GridViewRow)clickedButton.Parent.Parent; string x = clickedGridViewRow.Cells[AnotherCellNumberInTheSameRowWhoseValueYouWantToGet].Text; }
And you can link the button in each row of the gridview by specifying this code on the .aspx page where gridview is present.
<Columns> <asp:TemplateField ItemStyle-HorizontalAlign="Center"> <ItemTemplate> <asp:Button ID="Downloadbtn" Text="Download" runat="server" OnClick="Downloadbtn_Click"></asp:Button> </ItemTemplate> </asp:TemplateField> </Columns>
And you want the AutoGenerateColumns property of the Grid view to be true.
Hope this answers your question.
source share