AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Update DataGrid Issue - Value Not Changing
Posted by Myles Britten on  11/19/2010 2:27:04 PM Category: Asp.Net 2.0
Add to my favorites
Email to friend
I have looked at the article http://www.aspdotnetcodes.com/GridView_Insert_Edit_Update_Delete.aspx and based on code from it. However, I only allow update of existing data. The only problem that I am getting is when I select the update link. The value of the TextBox never changes. Also, I am using VB.Net in place of C#.

Here is the code for the RowUpdating:

Protected Sub grdEmployee_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)

Dim lblNumber As Label = DirectCast(Me.grdEmployee.Rows(e.RowIndex).FindControl("lblNumber"), Label)
Dim txtHours As TextBox = DirectCast(Me.grdEmployee.Rows(e.RowIndex).FindControl("txtHours"), TextBox)
If Not IsNumeric(txtHours.Text.Trim) Then Exit Sub
Dim rData As PositionControlClass.pctlDeptPosEmpBudgetItem
For Each rData In i_Employees
If rData.Number.Trim = lblNumber.Text.Trim Then
rData.Hours = CDec(txtHours.Text.Trim)
rData.FTE = Math.Round(rData.Hours / 80, 2)
Exit For
End If
Next

Me.grdEmployee.EditIndex = -1
PopulateTable()

End Sub

Post Your Reply Post New Question

 Viewer's Reply
Updated GridView Value Not Changing
Answered By Moderator1 on 11/19/2010 7:54:52 PM
Hi,

I suspect 2 code for this problem.

1. If rData.Number.Trim = lblNumber.Text.Trim Then

Make sure the comparision is correct in sense of DataType and Value, so the execution will go inside the If block statement.

2. Inside the If block, I found only you have assigned the value from the controls to the rData object.. But where you save this values to rData object before you bind the grid?
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
Sexy Web Design - Free 71 Page Preview!
Windows 8: 50 Questions and Answers You Need to Make a Decision (Normally $9.95)
Speech Technology Magazine