Error in getting value from a TemplateField

Hi all,

I'm implementing a generic GridView which can be bound to any datatable. Here are few things about GridView1:

GridView1.AutogenerateColumns = false;
GridView1.AutoGenerateEditButton = true;

DataSource is a DataTable, stored in Session variable.

I'm adding the Columns(TemplateField) to the grid in the code behind file.

It worked fine till populating the data onto the grid. When I click edit button, the values are populated in TextBoxes within the gridview. But After clicking the Update, I'm unable to access the data which are placed within the textboxes in the RowUpdating event.

I tried:
string ss = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("GridView1_ct" + (e.RowIndex + 2).ToString("100") + "id")).Text;

GridViewRow row = GridView1.Rows[e.RowIndex];
string field = (row.Cells[i+1].FindControl("id") as TextBox).Text;

GridViewRow row = GridView1.Rows[e.RowIndex];
string field = ((TextBox)row.Cells[i+1].Controls[0]).Text;

All the above three threw either NullReferenceException or ArgumentOutOfBoundsException.

I'm unable to access the new values which are placed in the textboxes. Plz help...

Thanks in advance...



  • Jus try like this,

    TextBox txtRevenue = (TextBox)GridViewLineItem.Rows[e.RowIndex].FindControl("[color=Red]txtRevenue[/color]");

    Where the text in color in [color=Red]RED[/color] is the id of the txtbox u hv give. There is no need to give as u hv given in the 1st statement. Dotnet will take care of the id assigning.
    "Always Smile :)"
  • Thanks for the reply. I was actually creating a dynamic data gridview, where the columns(based on the number of properties/columns in the datasource) are added at code-behind file. I got to add the Edit button from the code behind file but not like auto generate the edit button.
    After adding the edit button dynamically in the code behind, it got worked.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!