Problem capturing value from cell in gridview using GridView1_RowUpdating in ASP.net(VB). Getting error below.

DEK 0 Reputation points
2023-03-23T15:20:01.93+00:00
Line 73: 
Line 74:         'Compute Final Price
Line 75:         Dim ItemPrice As String = TryCast(GridView1.Rows(e.RowIndex).FindControl("Price"), TextBox).Text.ToString
Line 76:         hfFinalPrice.Value = hfItemQuanGrid.Value * ItemPrice
Line 77: 


ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,280 questions
{count} votes

1 answer

Sort by: Most helpful
  1. AgaveJoe 26,141 Reputation points
    2023-03-23T17:15:26.94+00:00

    You did not provide the error... Your code tries to multiple a string named ItemPrice by an unknown value (hfItemQuanGrid.Value). Convert ItemPrice and perhaps hfItemQuanGrid.Value to a numeric type using the TryParse() method.

    Imports System.Data
    
    Module Program
        Sub Main(args As String())
            Dim ItemPrice As String = "1.23"
            Dim Price As Decimal
    
            If (Decimal.TryParse(ItemPrice, Price)) Then
                Console.WriteLine("TryParse was successful.  The price is " & Price)
            Else
                Console.WriteLine("Unable to convert " & ItemPrice & " to a decimal")
            End If
        End Sub
    
    End Module
    
    0 comments No comments