hey guys i need help!! i am having problem with add cart...when i puchase and item it comes out this error
"Response.Redirect("~/Payment.aspx?total=" + total_price)"

bellow are my code.

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data.SqlClient
Imports System.Data

Partial Public Class Cart
    Inherits System.Web.UI.Page
    Private cart As ShoppingCart
    Private total_price As Decimal = 0

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        total_price = 0
        CheckTimeStamps()
        If Session("cart") Is Nothing Then
            cart = New ShoppingCart()
            Session("cart") = cart
        Else
            cart = DirectCast(Session("cart"), ShoppingCart)
        End If
        CartGridView.DataSource = cart.GetItems()
        If Not IsPostBack Then
            CartGridView.DataBind()
        End If
        total_price = calculateTotal()
        label_total.Text = total_price.ToString()
        CartGridView.SelectedIndex = -1

    End Sub

    Private Sub CheckTimeStamps()
        If IsExpired() Then
            Response.Redirect(Request.Url.OriginalString)
        Else
            Dim t As DateTime = DateTime.Now
            ViewState.Add("$$TimeStamp", t)
            Dim page As [String] = Request.Url.AbsoluteUri
            Session.Add(page + "_TimeStam", t)
        End If
    End Sub
    Private Function IsExpired() As Boolean
        Dim page As [String] = Request.Url.AbsoluteUri
        If Session(page + "_TimeStam") Is Nothing Then
            Return False
        ElseIf ViewState("$$TimeStamp") Is Nothing Then
            Return False
            'else if (Session[page + "_TimeStamp"].ToString() == ViewState["$$TimeStam"].ToString())
        ElseIf Session(page + "_TimeStamp") = ViewState("$$TimeStam") Then
            Return False
        Else
            Return True
        End If
    End Function
    'Continue Shopping Button
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        Response.Redirect("~/Product.aspx?return")
    End Sub

    Protected Sub CartGridView_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
        CartGridView.EditIndex = e.NewEditIndex
        CartGridView.DataBind()
    End Sub

    Protected Sub CartGridView_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
        total_price = 0
        Dim cell As DataControlFieldCell = DirectCast(CartGridView.Rows(e.RowIndex).Controls(3), DataControlFieldCell)
        Dim t As TextBox = DirectCast(cell.Controls(0), TextBox)
        Try
            Dim q As Integer = Integer.Parse(t.Text)
            cart.UpdateQuantity(e.RowIndex, q)
        Catch generatedExceptionName As FormatException
            e.Cancel = True
        End Try
        CartGridView.EditIndex = -1
        CartGridView.DataBind()
        total_price = calculateTotal()
        label_total.Text = total_price.ToString()
        CartGridView.SelectedIndex = -1

    End Sub

    Protected Sub CartGridView_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
        total_price = 0
        cart.DeleteItem(e.RowIndex)
        CartGridView.DataBind()
        total_price = calculateTotal()
        label_total.Text = total_price.ToString()
        CartGridView.SelectedIndex = -1
    End Sub
    'CheckOut Button
    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim usern As String = User.Identity.Name
        If usern = "" Then
            Response.Redirect("~/Account/Login.aspx?from=cart")
        Else
            '
            '            decimal count = 0;
            '            decimal row = CartGridView.Rows.Count;
            '            for (int i = 0; i < row; i++)
            '            {
            '                CartGridView.SelectedIndex = Convert.ToInt16(count);
            '                GridViewRow dr = CartGridView.SelectedRow;
            '                int id = Convert.ToInt32(dr.Cells[1].Text);
            '                int quant = Convert.ToInt32(dr.Cells[3].Text);
            '                String ConnectionStringDB = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DB01.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
            '
            '                SqlConnection conn = new SqlConnection(ConnectionStringDB);
            '                conn.Open();
            '
            '                SqlCommand command = conn.CreateCommand();
            '
            '                command.CommandText = "INSERT INTO Record (userid,appid,quantity) VALUES ('" + usern + "','" + id + "','" + quant + "')";
            '                command.ExecuteNonQuery();
            '                conn.Close();
            '
            '                count++;

        End If
    End Sub
    'Total calculate total price of all product
    Protected Function calculateTotal() As Decimal
        Dim count As Decimal = 0
        Dim row As Decimal = CartGridView.Rows.Count
        For i As Integer = 0 To row - 1
            CartGridView.SelectedIndex = Convert.ToInt16(count)
            Dim dr As GridViewRow = CartGridView.SelectedRow
            Dim price As Decimal = Convert.ToDecimal(dr.Cells(4).Text)
            total_price = total_price + price
            count += 1
        Next

        Return total_price
    End Function
    'If there is any update happen in the gridview, recalculate and assign the total price
    Protected Sub CartGridView_RowUpdated(ByVal sender As Object, ByVal e As GridViewUpdatedEventArgs)
        total_price = 0
        total_price = calculateTotal()
        label_total.Text = total_price.ToString()
        CartGridView.SelectedIndex = -1
    End Sub
    Protected Sub CartGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

    End Sub
End Class

this the error -"Conversion from string "~/Payment.aspx?total =" to type 'Double' is not valid."

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.