OnRowUpdate Does nothing When Clicked

Last Reply 10 hours ago By OpeyemiOg

Posted 4 days ago

Good day ASPeeps,

I have a gridview with OnRowEdit and OnRowDelete attributes set and the sqldatasource commands in place as shown below.

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" 
        SelectCommand="SELECT [Service], [Category], [Price], [Capitated], [TariffStatus], [Company] FROM [hServiceNHIS] WITH (NOLOCK) WHERE ([Company] = @RetainCode) ORDER BY [Service]ASC, [Category]ASC" 
        UpdateCommand="UPDATE hServiceNHIS SET Price = @Price, Capitated = @Capitated, TariffStatus = @TariffStatus WHERE ([Company] = @Company) AND Service = @Service" 
        DeleteCommand="DELETE FROM hServiceNHIS WHERE Service = @Service AND Company = @Company" FilterExpression="Service LIKE '%{0}%'">
            <asp:QueryStringParameter DefaultValue="#" Name="RetainCode" QueryStringField="RetainCode" Type="String" />
            <asp:ControlParameter ControlID="GridView1" Name="Company" PropertyName="SelectedDataKey"/>
            <asp:ControlParameter ControlID="GridView1" Name="Service" Type="String" />
            <asp:ControlParameter ControlID="GridView1" Name="Company" PropertyName="SelectedDataKey" />
            <asp:ControlParameter ControlID="GridView1" Name="Service" Type="String"  />
            <asp:ControlParameter ControlID="GridView1" Name="Capitated" />
            <asp:ControlParameter ControlID="GridView1" Name="TariffStatus"  />
        <asp:ControlParameter Name="Service" ControlID="txtSearch" PropertyName="Text" />

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="1000" AllowSorting="True" DataSourceID="SqlDataSource1" DataKeyNames="Company" AutoGenerateColumns="False" AlternatingRowStyle-BackColor="#ccffff" RowStyle-VerticalAlign="Top" EmptyDataText="No records has been added." EnableViewState="true" AutoGenerateEditButton="true" AutoGenerateDeleteButton="true" OnRowEditing="OnRowEditing" OnRowCancelingEdit="OnRowCancelingEdit" OnRowUpdating="OnRowUpdating" OnRowDeleting="OnRowDeleting">
            <asp:BoundField DataField="Company" HeaderText="Company" SortExpression="Company" ReadOnly="true" />
            <asp:BoundField DataField="Service" HeaderText="Service" SortExpression="Service" ReadOnly="true" />
            <asp:BoundField DataField="Category" HeaderText="Category" SortExpression="Category" ReadOnly="true" />
            <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
            <asp:BoundField DataField="Capitated" HeaderText="Capitated" SortExpression="Capitated" />
            <asp:BoundField DataField="TariffStatus" HeaderText="TariffStatus" SortExpression="TariffStatus" />

And i have inherited the class from my .vb file below


Protected Sub OnRowUpdating(sender As Object, e As GridViewUpdateEventArgs)
        Dim row As GridViewRow = GridView1.Rows(e.RowIndex)
        Dim Company As String = TryCast(row.Cells(5).Controls(0), TextBox).Text
        Dim Service As String = TryCast(row.Cells(5).Controls(0), TextBox).Text
        Dim Price As Decimal = Decimal.TryParse(row.Cells(5).Controls(0).ToString, Price)
        Dim Capitated As String = TryCast(row.Cells(5).Controls(0), TextBox).Text
        Dim TariffStatus As String = TryCast(row.Cells(5).Controls(0), TextBox).Text

        Dim constr As String = ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString
        Using con As New SqlConnection(constr)
            Using cmd As New SqlCommand("UPDATE hServiceNHIS SET Price = @Price, Capitated = @Capitated, TariffStatus = @TariffStatus WHERE Company = @Company AND Service = @Service")
                cmd.Parameters.AddWithValue("@Company", Company)
                cmd.Parameters.AddWithValue("@Service", Service)
                cmd.Parameters.AddWithValue("@Price", Price)
                cmd.Parameters.AddWithValue("@Capitated", Capitated)
                cmd.Parameters.AddWithValue("@TariffStatus", TariffStatus)
                cmd.Connection = con

            End Using
        End Using
        GridView1.EditIndex = -1
    End Sub

In my gridview when i clicjk the edit button the inline edit form appears. I enter my values and hit update but nothing happens no errors it just reloads the page with no changes made.


Please help been battling to sort this out



You are viewing reply posted by: OpeyemiOg 4 days ago.
Posted 4 days ago

Thnx for the tip dhamendr,

i commented out


an replaced with


I ran the cod

If cmd.ExecuteNonQuery() Then
                    Dim message As String = "Record was updated successfully!"
                    Dim url As String = "StfLve.aspx"
                    Dim script As String = "window.onload = function(){ alert('"
                    script += message
                    script += "');"
                    script += "window.location = '"
                    script += url
                    script += "'; }"
                    ClientScript.RegisterStartupScript(Me.GetType(), "Redirect", script, True)
                Else : Dim message As String = "Error occured! Culd not update"
                    Dim sb As New System.Text.StringBuilder()

                    sb.Append("<script type = 'text/javascript'>")






                    ClientScript.RegisterClientScriptBlock(Me.GetType(), "alert", sb.ToString())
                End If

And the else part was triggered indicating an error.


Problem is where is the error from? I suspect the Decimal.Tryparse is not well constructed. What do you think?

With Admiration

I agree, here is the link: http://e-iceblue.com/free-api