Asp.Net News
Free Tech Magazines
Asp.Net Web Hosting
Suggest Us
Link to Us
Feeds Subscription
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 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

Me.grdEmployee.EditIndex = -1

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

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
Easing the Migration to Microsoft SQL Server 2005
No Nonsense XML Web Development With PHP - Free 146 Page Preview!
Sexy Web Design - Free 71 Page Preview!