Update decimal value on UpdateEvent in GridView using VB.Net in ASP.Net

Last Reply on Nov 08, 2016 01:46 AM By Indresh

Posted on Nov 07, 2016 01:51 AM

Hi

I have issue in updating the nemerical value with decimal using asp.net

here is my code

    Protected Sub gv_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gv.RowUpdating
        Dim dt As DataTable = Session("Grid_Details")
        Dim txtQtyAvail As TextBox = gv.Rows(e.RowIndex).Cells(7).Controls(0)
        Dim reg_exp As New Regex("^\d+$")

        Dim arow As GridViewRow = gv.Rows(e.RowIndex)
        If Not reg_exp.IsMatch(DirectCast(arow.Cells(7).Controls(0), TextBox).Text) Then
            DirectCast(arow.Cells(7).Controls(0), TextBox).Text = "Only number positive"
            DirectCast(arow.Cells(7).Controls(0), TextBox).ForeColor = Drawing.Color.Red
            e.Cancel = True
        Else
            Dim number_pro As Integer = Integer.Parse(txtQtyAvail.Text)
            If number_pro = 0 Then
                dt.Rows(e.RowIndex).Delete()
                dt.AcceptChanges()
                Session("Grid_Details") = dt
                load_Grid_Details()
            Else
                dt.Rows(e.RowIndex)("qtyavailable") = number_pro
                dt.AcceptChanges()
                Session("Grid_Details") = dt
                gv.EditIndex = -1
                load_Grid_Details()

            End If
        End If
    End Sub

I am using Session. below is session code

 

    Sub CreatGridDetails()
        Dim dt As New DataTable
        If dt.TableName.Contains("tbl_GridDetails") = True Then
            Exit Sub
        Else
            dt = New DataTable("tbl_GridDetails")

            dt.Columns.Add("rmcode", GetType(String))
            dt.Columns.Add("rmdesc", GetType(String))
            dt.Columns.Add("specs", GetType(String))
            dt.Columns.Add("uom", GetType(String))
            dt.Columns.Add("qty", GetType(Decimal))
            dt.Columns.Add("qtyavail", GetType(Decimal))
        End If
        dt.Rows.Clear()
        Session("Grid_Details") = dt
        gv.DataSource = dt
        gv.DataBind()

    End Sub

Normal number like 234 can be entered. but cannot enter 234.90 like this

Pls advice me how to do it

thank you

maideen

Posted on Nov 08, 2016 01:46 AM