ProTech's home page

ProTech-Online.com

Microsoft c# ASPX code example for adding items to a shopping cart web session.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Web.Security;
public partial class catalog : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void OnSelectedIndexChanged()
    {
        try
        {
            SqlConnection myConnection = new SqlConnection(WebConfigurationManager.ConnectionStrings["TestConnectionString"].ToString());
            myConnection.Open();
            SqlCommand myCommand = new SqlCommand("addto_carts", myConnection);
            myCommand.CommandType = System.Data.CommandType.StoredProcedure;
            myCommand.Parameters.AddWithValue("@sessionid", Session["SoftwareID"]);
            myCommand.Parameters.AddWithValue("@userid", User.Identity.Name);
            myCommand.Parameters.AddWithValue("@itemid", GridView1.DataKeys[GridView1.SelectedIndex].Value);
            myCommand.ExecuteNonQuery();
            myConnection.Close();
            Master.checksession();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
}


Copyright © 2013 ProTechs-Online.com; All rights reserved.