Why doesn't TextBox control get updated

T

Tuomo

Hi!

I have a form (System.Web.UI.Page) that contains a DataGrid control and a
DataTable that contains values for the data grid and that is data bound to
the DataGrid. When I switch the grid to edit mode (e.g. if I set
DataGrid.EditItemIndex = 0) the values in the data table are displayed
correctly in TextBox controls in the DataGrid. Then, if I cause a postback
(e.g. pressing a button) and I set a new value into the data table into a
certain data field (e.g. in the Page_Load method) the TextBox contains the
old value although the data table field where the text box in data bound
contains a new value.

Why doesn't the TextBox control get updated?

I have tested that other controls such as Labels, show the current value of
the data table field but I don't understand why TextBox doesn't get a new
value.

Thank you.

BR, Tuomo
 
D

Daniel

Make sure in your page load that you are updating or re-popuating the
datagrid again.

so in your page load

if(!(Page.IsPostBack))
{
//everything in here fires only the first time your page is loaded
}
else
{
//reload your data grid here ad everytime you post back it will be
forced to update (assuming your changes
//were saved to your datasource)
}
 
T

Tuomo

Thank you Daniel.

I bind the data again to the data grid after I have set a new value to the
data table field. I do it in this way:

DgrdValues.DataSource = dtTest
DgrdValues.DataBind()

I have also ItemDataBound handler for the data grid but I don't handle the
text box column in any way in the handler.

The thing that I don't understand is that all other controls such as labels
and hyperlinks show their new values but text boxes don't. Could this be a
ViewState problem or even a bug in the text box or data grid control? Or
could there be some kind of refresh function for the data grid of text box..

BR, Tuomo
 
T

Tuomo

I found a little bit curious solution to the problem. I create a new text
box control in the ItemDataBound method and at the same I generate a new ID
for the control. That causes the text box updating its value.

I checked that this is a problem only when the text box is used in a data
grid. The text box updates normally its value when used without a data grid.
It seems that this could be some kind of view state problem, I think.

Do you have any ideaos or better solutions according to this issue? Could
someone give an explanation of this interesting logic? This is getting
interesting..

BR,
Tuomo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top