Why doesn't TextBox control get updated

Discussion in 'ASP .Net Datagrid Control' started by Tuomo, Dec 30, 2005.

  1. Tuomo

    Tuomo Guest

    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
     
    Tuomo, Dec 30, 2005
    #1
    1. Advertising

  2. Tuomo

    Daniel Guest

    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)
    }

    "Tuomo" <> wrote in message
    news:...
    > 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
    >
     
    Daniel, Dec 30, 2005
    #2
    1. Advertising

  3. Tuomo

    Tuomo Guest

    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



    "Daniel" <> wrote in message
    news:...
    > 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)
    > }
    >
     
    Tuomo, Jan 2, 2006
    #3
  4. Tuomo

    Tuomo Guest

    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

    "Tuomo" <> wrote in message
    news:...
    > 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
    >
    >
    >
    > "Daniel" <> wrote in message
    > news:...
    >> 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)
    >> }
    >>

    >
    >
     
    Tuomo, Jan 2, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TmV3YXNwcw==?=
    Replies:
    0
    Views:
    704
    =?Utf-8?B?TmV3YXNwcw==?=
    Jun 12, 2004
  2. =?Utf-8?B?S2V2aW4=?=
    Replies:
    3
    Views:
    11,452
    Walter Wang [MSFT]
    Jun 17, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,090
    Smokey Grindel
    Dec 2, 2006
  4. Dmitry Korolyov

    Datagrid not updated during delete, but updated during insert and update

    Dmitry Korolyov, Sep 22, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    424
    Dmitry Korolyov
    Sep 22, 2003
  5. ErwinP
    Replies:
    1
    Views:
    772
    ErwinP
    Aug 19, 2005
Loading...

Share This Page