Cant get user-entered values in GridView

A

Arthur Dent

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
 
C

CaffieneRush

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()).
 
A

Arthur Dent

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!
 

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
474,265
Messages
2,571,071
Members
48,771
Latest member
ElysaD

Latest Threads

Top