views:

2186

answers:

2

Hi,

ASP.NET 1.1 - I have a datagrid on an aspx page that is databound and displays a value within a textbox. The user is able to change this value, then click on a button where the code behind basically iterates through each DataGridItem in the grid, does a FindControl for the ID of the textbox then assigns the .Text value to a variable which is then used to update the database. The datagrid is rebound with the new values.

The issue I'm having is that when assigning the .Text value to the variable, the value being retrieved is the original databound value and not the newly entered user value. Any ideas as to what may be causing this behaviour?

Code sample:

foreach(DataGridItem dgi in exGrid.Items)
  {
   TextBox Text1 = (TextBox)dgi.FindControl("TextID");
   string exValue = Text1.Text; //This is retrieving the original bound value not the newly entered value
            // do stuff with the new value
        }

Thanks

A: 

So the code sample is from your button click event?

Are you sure you are not rebinding your datasource on postback?

Aros
Hi Aros,Yes it is in the button_click event. Just checking the binding in page_load... Damn - that's it - binding outside of if(!Page.IsPostBack) being called prior to button_click.Thanks
acripps
A: 

When are you attempting to retrieve the value from the TextBox? i.e. when is the code sample you provided being executed?

If you aren't already, you'll want to set up a handler method for the ItemCommand event of the DataGrid. You should be looking for the new TextBox value within that method. You should also make sure your DataGrid is not being re-databound on postback.

I would also highly recommend reading through Scott Mitchell's excellent article series on using the DataGrid control and all of it's functions: http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

aweber1
Thanks for the answer - it was due to the datagrid being rebound on postback but Aros got in first. Will check out the link
acripps