Reputation: 957
I need to get the value of a cell of a GridView. When the user click on the grid, I need to know which line button, and then get the value of the cell. I'm trying to use the following code, but not work.
protected void gvSearch_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
int row = Convert.ToInt32(e.CommandArgument);
string tst = gvSearch.Rows[row].Cells[1].Text;
}
}
I do not know if I'm using the right event to get on my goal. If someone can help me, I thank you.
Upvotes: 1
Views: 20093
Reputation: 16
You can use this code
protected void gvSearch_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
string pc = gVSearch.Rows[int.Parse(e.CommandArgument.ToString())].Cells[1].Text;
}
}
Upvotes: 0
Reputation: 957
I found a solution!
Am using BoundField.
<asp:BoundField HeaderText="Código Área" DataField=" <asp:BoundField HeaderText="Denominação Área" DataField="areaName" />
protected void gvSearch_SelectedIndexChanged(object sender, EventArgs e)
{
String lastName = gvSearch.SelectedRow.Cells[1].Text;
}
Thanks everyone!
Upvotes: 2