I am trying to use the update method for the gridview and its simply returning null
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox Currency = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("Currency"));
GridView1.EditIndex = -1;
if (!Page.IsPostBack)
{
FillTravelers();
}
}
Any ideas? when I press update it just returns the field to its previous value but returns nothing.
Thanks
As your Gridview is in its simplest form with no controls defined in the gridview (and hence there is no Currency textbox defined in the GridView), please check the datasource of GridView1 which I assume would be a Datatable.
Then you need to identify which column of the Datatable is the Currency column.
For e.g., for the below datatable, it would be column 2.
Based on this, you can retrieve your updated Currency value using the following code below.
Please note that if the Currency column is different above, then you need to change the index of rows.Cells[index].Controls[0] too. For e.g., if Currency is at column 5, then the txtCurrency definition becomes:
If you are not able to figure out the column index of the datatable easily (or if you are using a more complicated datasource), then, assuming the GridView1 does not have too many columns, I would recommend trying to increment the Cells index step by step until you see the updated value in the Watch for row.Cells[index].Controls[0] while debugging.
Edit: (Adding code to retrieve the column index of the Currency column)
You can pass “Currency” as a string and the OracleDataReader instance to the below method and this should give you the column index (or it gives you -1 if there is no Currency column in the OracleDataReader).
Then in the actual code, you can modify add 1 to the cell index as shown below because the cell index is not zero based like the column index.