Asp.Net News
Free Tech Magazines
Asp.Net Web Hosting
Suggest Us
Link to Us
Feeds Subscription
Questions & Answers
Tips & Tricks
 RowEditing in a Gridview
Posted by Kate Tate on  10/11/2007 5:37:10 PM Category: Asp.Net 2.0
Add to my favorites
Email to friend
Hello! I am a newbie and need some help. I am working in Asp.Net 2.0 and using VB.

I have a grid view that is set to edit and upon edit of one text field it runs a calculation then puts the results of that equation into the text box of another field upon "update". It works great on my first page, but when I copied and pasted it into another page it doesn't work quite the same.

It will update the info on the "miles" but not run the calculation on the "amount" changing the amount to the results of the calculation. Ironically and irritatingly enough, it will run the calculation if upon hitting the edit you tab to the "amount" field and hit the delete button on the keyboard. It will then update perfectly. However, if you leave the original amount in, hit the space bar or put in a "0" it will not perform the calculation.

Any and all suggestions would be extremely welcome!



Here is the code:

Protected Sub gvAuthApproval_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvAuthApproval.RowUpdating

'This allows updating of the miles in the gridview and recalculating the amount.

Dim amount As Decimal
Dim txtMiles As TextBox = CType(gvAuthApproval.Rows(e.RowIndex).FindControl("txtMiles"), TextBox)
Dim txtAmount As TextBox = CType(gvAuthApproval.Rows(e.RowIndex).FindControl("txtAmount"), TextBox)

If txtMiles.Text <> "" Then

amount = Decimal.Parse(txtMiles.Text) * 0.485
txtAmount.Text = amount.ToString("###.#")
End If

Me.odsAuthExpense.UpdateParameters("amount").DefaultValue = amount
End Sub

Post Your Reply Post New Question

 Viewer's Reply
Could you tell us more precisely..
Answered By Moderator1 on 10/15/2007 6:02:59 AM

Thanks for posting your question in our website. We could understand your problem.

when the txtMiles.Text is empty you to convert it as zero. then only it will calculate. else the application will treat it as an empty field and according to your code it will not callculate.

Post Your Reply If you still have problem, post it again under this reply for better response.

Sponsored by
The Art & Science of JavaScript - Free 100 Page Preview!
Windows 8: 50 Questions and Answers You Need to Make a Decision (Normally $9.95)