The default behavior of
GridView
control is to perform edit and update one row at time. It seems like you are trying to use an Update
Button
outside your
GridView
which there's no way for you to identify which row you are actually editing. To update a row, you should be handling the
RowUpdating
event to do that and then handle your update logic there instead.
Here are a couple of examples:
Using TemplateFields
Adding Rows in GridView with Edit, Update and Delete Functionality[
^]
Using BoundFields
GridView Insert, Edit, Update and Delete – The Ado.Net way[
^]
Now, if you are trying to select a row from
GridView
and populate the selected values in your
TextBox
that is outside your GridView then you can get rid of the
RowEditing
event and Edit
ButtonField
. You would simply need to setup the
ShowSelectButton CommandField
in the
GridView
like:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" >
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField />
<asp:BoundField />
</Columns>
</asp:GridView>
and at
SelectedIndexChanged
event you can do something like this to get the selected row data and populate your TextBox:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e){
TextBox1.Text = GridView1.SelectedRow.Cells[0].Text;
TextBox2.Text = GridView1.SelectedRow.Cells[1].Text;
}
Then you can use the code that what you have in your Update
Button
that is outside the
GridView
to update the data.