Jump to content

Updating datagrid values


Guest shet_ravi
 Share

Recommended Posts

Guest shet_ravi

Hi! every body, I have placed a datagrid and bound it to database.The grid is editable through the edit-update buttons. On the update event handler i use this code to retrieve the updated values from the text boxes ---- Dim strMonth as String = CType(e.Item.Cells(2).Controls(0), TextBox).TextBut strangely it retrieves the original values instead of the updated values. I have seen this code in numerous sites, but it does not work in this case.Can any body help me out. :)

Link to comment
Share on other sites

you will be populating the datagrid during the Page_Load. Check if you are doing that inside this PostBack condition. If not try doing it.Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadIf Not (IsPostBack) Then' Code to Populate DatagridEndIFEnd SubWhen the Update button is clicked then the page is posted back, and if you populating without checking the postback then the DG will be populated frm DB and thats why u are getting the old Data again.

Link to comment
Share on other sites

you will be populating the datagrid during the Page_Load. Check if you are doing that inside this PostBack condition. If not try doing it.Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadIf Not (IsPostBack) Then' Code to Populate DatagridEndIFEnd SubWhen the Update button is clicked then the page is posted back, and if you populating without checking the postback then the DG will be populated frm DB and thats why u are getting the old Data again.

I had this happen to me many times...still gets past me once and a while. It is silly once you know about it but it makes sense. I wasted lots of time trying to solve this when I was starting out. Pain in hte butt. :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...