Cant get user-entered values in GridView

Discussion in 'ASP .Net Datagrid Control' started by Arthur Dent, Mar 13, 2006.

  1. Arthur Dent

    Arthur Dent Guest

    Okay, this should be really simple, and maybe im just missing something
    totally obvious, but i cannot figure this out. I did this all the time in
    ASP.NET 1.1 with no problems.

    I have a GridView which has a column that is a template column, and has a
    textbox in the itemtemplate. There is one button in the footer of the grid
    for "save"; so the user can type in changes to a bunch of rows, and then
    click save, and my code iterates essentially as so:

    For Each gr As GridViewRow In grid.Rows: SaveRow(gr): Next

    This way they can change a bunch of rows and then save instead of doing
    change a row, save, change a row, save, change a row, save, change a row,
    save.

    So my code (pseudo-code) looks like this:

    Sub btnSave_Click
    For Each gr As GridViewRow in grid.Rows
    Dim newValue as string =
    CType(gr.FindControl("txtValue"),TextBox).Text

    Dim SQL as string = "Some Sql using the new value"
    ExecuteSQL
    Next
    End Sub

    The problem is, when i get the Text property from the textbox, it gives me
    the OLD value to which it was initially bound, instead of giving me the new
    value which the user typed in. Why? How am i supposed to get the user's new
    data?
    Please HELP!!

    Thanks in advance,
    - Arthur Dent
     
    Arthur Dent, Mar 13, 2006
    #1
    1. Advertising

  2. Hi,
    Try it...
    http://www.dotnetjohn.com/articles.aspx?articleid=83

    It looks what you are looking for...

    best luck
    ...
    "Arthur Dent" <> wrote in message
    news:...
    > Okay, this should be really simple, and maybe im just missing something
    > totally obvious, but i cannot figure this out. I did this all the time in
    > ASP.NET 1.1 with no problems.
    >
    > I have a GridView which has a column that is a template column, and has a
    > textbox in the itemtemplate. There is one button in the footer of the grid
    > for "save"; so the user can type in changes to a bunch of rows, and then
    > click save, and my code iterates essentially as so:
    >
    > For Each gr As GridViewRow In grid.Rows: SaveRow(gr): Next
    >
    > This way they can change a bunch of rows and then save instead of doing
    > change a row, save, change a row, save, change a row, save, change a row,
    > save.
    >
    > So my code (pseudo-code) looks like this:
    >
    > Sub btnSave_Click
    > For Each gr As GridViewRow in grid.Rows
    > Dim newValue as string =
    > CType(gr.FindControl("txtValue"),TextBox).Text
    >
    > Dim SQL as string = "Some Sql using the new value"
    > ExecuteSQL
    > Next
    > End Sub
    >
    > The problem is, when i get the Text property from the textbox, it gives me
    > the OLD value to which it was initially bound, instead of giving me the
    > new value which the user typed in. Why? How am i supposed to get the
    > user's new data?
    > Please HELP!!
    >
    > Thanks in advance,
    > - Arthur Dent
    >
     
    Munawar Hussain, Mar 14, 2006
    #2
    1. Advertising

  3. Arthur Dent

    Guest

    Check to see if you've over written your gridview values in the events
    before getting to your postback event handler (btnSave_Click()) and
    after ASP.NET calls LoadViewState (eg. Page_Load()).
     
    , Mar 14, 2006
    #3
  4. Arthur Dent

    Arthur Dent Guest

    Yes, this was it.... in my Page_Load, i have my "If Not IsPostBack" block
    commented out, ... why, who knows.

    Uncommented that, and now it works as perfect.
    Thanks for the "extra set of eyes"!

    CheerZ!


    <> wrote in message
    news:...
    > Check to see if you've over written your gridview values in the events
    > before getting to your postback event handler (btnSave_Click()) and
    > after ASP.NET calls LoadViewState (eg. Page_Load()).
    >
     
    Arthur Dent, Mar 14, 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. TN Bella
    Replies:
    1
    Views:
    1,558
    TN Bella
    Jul 1, 2004
  2. =?Utf-8?B?dmluZWV0YmF0dGE=?=

    How to access values entered in User control in the main page.

    =?Utf-8?B?dmluZWV0YmF0dGE=?=, Nov 6, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    556
  3. Nagaraj
    Replies:
    1
    Views:
    923
    Lionel B
    Mar 1, 2007
  4. vineetbatta

    How to access values entered in User control in the main page.

    vineetbatta, Nov 6, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    152
    Scott Mitchell [MVP]
    Nov 7, 2004
  5. vineetbatta

    How to access values entered in User control in the main page.

    vineetbatta, Nov 6, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    196
    Scott Mitchell [MVP]
    Nov 7, 2004
Loading...

Share This Page