Example of shopping cart using asp.net with C#

Login.aspx

<%@ Page Language="C#" AutoEventWireup="true"

CodeFile="loginpage.aspx.cs" Inherits="loginpage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0

Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
        <tr>
            <td>
                <asp:Label ID="Label1" runat="server"

Text="enter your name"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="TextBox1"

runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="Label2" runat="server"

Text="enter your username"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="TextBox2"

runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="Label3" runat="server"

Text="enter your password"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="TextBox3"

runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Button ID="Button2" runat="server"

Text="ragister"
                    onclick="Button2_Click" /></td>
            <td>
                <asp:Button ID="Button1" runat="server"

Text="submit" onclick="Button1_Click" /></td>
                <td>
                    <asp:Label ID="Label4" runat="server"

Text=""></asp:Label>
                    </td>
        </tr>
    </table>
    </div>
    </form>
</body>
</html>

login.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class loginpage : System.Web.UI.Page
{
   
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["unm"] = TextBox2.Text;
        Session["pwd"] = TextBox3.Text;

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
       
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        conn.Open();
        string q1 = "select * from data where username='" + TextBox2.Text + "' and password='" + TextBox3.Text + "'";
        SqlCommand cmd = new SqlCommand(q1, conn);
        SqlDataReader dr = cmd.ExecuteReader();
        bool b = dr.HasRows;
        if (b)
        {
            Response.Redirect("~/mainpage.aspx?tnm="+TextBox2.Text+"&nm="+TextBox1.Text);
            //Response.Redirect("~/masterdata/studelogview.aspx?tnm=" + TextBox1.Text + " &unm=" + TextBox2.Text + " &paa=" + TextBox3.Text + "");
        }
        else
        {
            Label4.Text = "sorry yar try again";
        }

       
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
       
       
        string q = " insert into data(username, password)values('" + TextBox2.Text + "','" + TextBox3.Text + "')";
        SqlCommand cmd = new SqlCommand(q, conn);
        SqlCommand cmd2 = new SqlCommand("CREATE TABLE   " + TextBox2.Text + " (" + "Id int IDENTITY(1,1) NOT NULL PRIMARY KEY," + "image varchar(200)," + "producname varchar(50)," + "price int," + "quantity int," + "total int)", conn);

        conn.Open();
        SqlCommand cmd3 = new SqlCommand("SELECT 1  FROM INFORMATION_SCHEMA.TABLES WHERE  TABLE_NAME='" + TextBox3.Text + "'", conn);
        SqlDataReader dr = cmd3.ExecuteReader();
        bool b = dr.HasRows;
        dr.Close();
        if (b)
        {
            System.Web.HttpContext.Current.Response.Write("<SCRIPT> alert('this name is already is Registrated');</SCRIPT>");

        }
        else
        {
            cmd2.ExecuteNonQuery();
            cmd.ExecuteNonQuery();
           
        }
    }
}

mainpage.aspx

<%@ Page Language="C#" AutoEventWireup="true" 

CodeFile="mainpage.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0

Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            width: 184px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
                <tr>
                    <td class="style1">
                        <a href="watch.aspx" >
                            <asp:Image ID="Image1"

runat="server" ImageUrl="~/image/watch.jpeg"
                            Height="107px" Width="117px" 

/> </a><br />
                       
                        <asp:Button ID="Button7"

runat="server" Text="show all item of watch"
                            onclick="Button7_Click" />
                    </td>
                   <td>
                        <a href="racket.aspx" >
                            <asp:Image ID="Image2"

runat="server" ImageUrl="~/image/racket.jpeg"
                            Height="131px" Width="134px" 

/> </a><br />
                           
                       <asp:Button ID="Button2"

runat="server" Text="Add to card"
                            onclick="Button2_Click" />
                    </td>
                    <td>
                        <a href="toy.aspx" >
                            <asp:Image ID="Image3"

runat="server" ImageUrl="~/image/toys.jpeg"
                            Height="88px" Width="98px"  />

</a><br />
                            <asp:Label ID="Label3"

runat="server" Text="price $25"></asp:Label>
                            <asp:Button ID="Button3"

runat="server" Text="Add to card"
                            onclick="Button3_Click" />
                    </td>
                    </tr>
                    <tr>
                    <td class="style1">
                        <a href="perfum.aspx" >
                            <asp:Image ID="Image4"

runat="server" ImageUrl="~/image/perfums.jpeg"
                            Height="92px" Width="122px" 

/> </a><br />
                            <asp:Label ID="Label4"

runat="server" Text="price $350"></asp:Label>
                            <asp:Button ID="Button4"

runat="server" Text="Add to card"
                            onclick="Button4_Click" />
                    </td>
                    <td>
                        <a href="wallet.aspx" >
                            <asp:Image ID="Image5"

runat="server" ImageUrl="~/image/wallet.jpeg"
                            Height="90px" Width="130px" 

/> </a><br />
                            <asp:Label ID="Label6"

runat="server" Text="price $65"></asp:Label>
                            <asp:Button ID="Button5"

runat="server" Text="Add to card"
                            onclick="Button5_Click" />
                    </td>
                    <td>
                        <a href="mobile.aspx" >
                            <asp:Image ID="Image6"

runat="server" ImageUrl="~/image/mobiles.jpeg"
                            Height="87px" Width="104px" 

/> </a><br />
                            <asp:Label ID="Label5"

runat="server" Text="price $600"></asp:Label>
                            <asp:Button ID="Button6"

runat="server" Text="Add to card"
                            onclick="Button6_Click" />
                    </td>
                </tr>
                <tr>
                    <br />
                    <br />
                    <br />
                    <td class="style1">
                        <asp:Button ID="Button1"

runat="server" Text="show your purches item"
                            onclick="Button1_Click"

Width="153px" /></td>
                </tr>
              
        </table>
       
        <asp:Label ID="Label8" runat="server" Text=""

Font-Bold="true" ForeColor="#3399CC"></asp:Label>
      
         <asp:Button ID="Button8" runat="server"

Text="Logout" BackColor="Blue"
            ForeColor="White" Font-Bold="true"

Font-Size="Larger" onclick="Button8_Click" />
       
        
        <asp:Label ID="Label7" runat="server" Text="your

total is"></asp:Label>
       
        
       
       
       
                            <asp:GridView ID="GridView1"

runat="server"
            onrowcommand="GridView1_RowCommand" 

DataKeyNames="image"
            AutoGenerateColumns="False"

onrowediting="GridView1_RowEditing"
           

onrowcancelingedit="GridView1_RowCancelingEdit"
                onrowupdating="GridView1_RowUpdating"

ShowFooter="True"
            onrowdatabound="GridView1_RowDataBound">
            <Columns>
           
                          <asp:TemplateField

HeaderText="image">
                            <ItemTemplate>
                                    <asp:Image ID="image1"

 runat="server" Height="60px" Width="60px"/>
                            </ItemTemplate>
                          </asp:TemplateField>
                          
                <asp:TemplateField HeaderText="id">
                   <ItemTemplate>
                       <asp:Label ID="Label1"

runat="server" Text='<% # Eval("id") %>'></asp:Label>
                   </ItemTemplate>
                </asp:TemplateField>
               
               
                <asp:TemplateField

HeaderText="producname">
                   <ItemTemplate>
                       <asp:Label ID="Label2"

runat="server" Text='<% # Eval("producname")

%>'></asp:Label>
                   </ItemTemplate>
                 </asp:TemplateField>
                <asp:TemplateField HeaderText="price">
                   <ItemTemplate>
                       <asp:Label ID="Label3"

runat="server" Text='<% # Eval("price") %>'></asp:Label>
                   </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="quntity">
                   <ItemTemplate>
                       <asp:Label ID="Label4"

runat="server" Text='<% # Eval("quantity")

%>'></asp:Label>
                   </ItemTemplate>
                   <EditItemTemplate>
                       <asp:TextBox ID="TextBox1"

runat="server" Text='<% # Eval("quantity")

%>'></asp:TextBox>
                   </EditItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="total">
                   <ItemTemplate>
                       <asp:Label ID="Label5"

runat="server" Text='<% # Eval("total") %>'></asp:Label>
                   </ItemTemplate>
                   <FooterTemplate>
                       <asp:Label ID="Label10"

runat="server" Text='<% # Eval("total") %>'></asp:Label>
                   </FooterTemplate>
                 </asp:TemplateField>
               
                <asp:TemplateField HeaderText="Edit">
                   <ItemTemplate>
                       <asp:ImageButton ID="ImageButton2"

runat="server" ImageUrl="~/image/toys.jpeg" Width="30px"

CommandName="edit" CommandArgument='<% # Eval("id") %>' 

ToolTip="edit"/>
                   </ItemTemplate>
                   <EditItemTemplate>
                       <asp:ImageButton ID="update"

runat="server" CommandName="update"

ImageUrl="~/image/wallet.jpeg" Width="50px" Height="30px"

/>
                       <asp:ImageButton ID="cancel"

runat="server" CommandName="cancel"

ImageUrl="~/image/watch.jpeg" Width="50px" Height="30px"

/>
                   </EditItemTemplate>
                </asp:TemplateField>
               
               
                <asp:TemplateField HeaderText="Delete">
                   <ItemTemplate>
                    <asp:ImageButton ID="ImageButton1"

ToolTip="remove" runat="server"

ImageUrl="~/image/racket.jpeg" Width="30px"

CommandName="del" CommandArgument='<% # Eval("id") %>' />
                   </ItemTemplate>
                </asp:TemplateField>
                                               
               
                                               
            </Columns>
       </asp:GridView>
       
                   
               
        <asp:Label ID="Label9" runat="server"

Text="Label"></asp:Label>                   
   
    </div>
    </form>
</body>
</html>

mainpage.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{

    Image i;
    SqlConnection cn = new SqlConnection(@"Data Source=SQLDB;User ID=Demod;Password=Demo1@");
    DataTable dt = new DataTable();

    protected void Page_Load(object sender, EventArgs e)
    {
        string wel=Request.QueryString["nm"];
        Label8.Text ="WELL COME"+ wel;

       
    }
    public string totaldata()
    {
       
       
        /*string tot1 = null;
        foreach (GridViewRow r in GridView1.Rows)
        {
          
            Label tot = (Label)GridView1.Rows[r.RowIndex].FindControl("Label5");
            tot1 = tot.Text;

        }*/
        cn.Close();
        string tablenm = Session["unm"].ToString();
        Label9.Text = tablenm;
        string q = "select sum(total) from " + tablenm + "";
        SqlCommand cmd = new SqlCommand(q, cn);
        cn.Open();
        string to = cmd.ExecuteScalar().ToString();
        Label7.Text ="your total is"+ to;

        return to;
       
    }
   
    public void showgrid()
    {
       
        string tablenm = Session["unm"].ToString();

        SqlDataAdapter da = new SqlDataAdapter("select image,id,producname,price,quantity,price*quantity as total from "+tablenm+"", cn);
        da.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
        foreach (GridViewRow r in GridView1.Rows)
        {
            i = (Image)(GridView1.Rows[r.RowIndex].Cells[0].FindControl("Image1"));
            string s = GridView1.DataKeys[r.RowIndex].Value.ToString();
            i.ImageUrl = s.ToString();
            i.DataBind();

        }
        totaldata();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
      
        string tablenm = Session["unm"].ToString();
        if (e.CommandName == "del")
        {
            string s = "delete from "+tablenm+" where id='" + e.CommandArgument.ToString() + "'";
            SqlCommand cmd = new SqlCommand(s, cn);
            cn.Open();
            cmd.ExecuteNonQuery();
          
            showgrid();
            cn.Close();
        }
        else if (e.CommandName == "cancel")
        {
            GridView1.EditIndex = -1;
            showgrid();
        }
    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        showgrid();
    }

    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {

    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

       
        string tablenm = Session["unm"].ToString();
        Label lb = (Label)GridView1.Rows[e.RowIndex].FindControl("Label1");
        Label produ = (Label)GridView1.Rows[e.RowIndex].FindControl("Label2");
        TextBox txtname = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1");
        string q = "update "+tablenm+" set quantity='" + txtname.Text + "' where id='" + lb.Text + "'";
        string q1 = "update " + tablenm + " set total=(price*quantity) where id='" + lb.Text + "'";
        cn.Open();
        SqlCommand cmd = new SqlCommand(q, cn);
        SqlCommand cmd1 = new SqlCommand(q1, cn);
        cmd.ExecuteNonQuery();
        cmd1.ExecuteNonQuery();
        GridView1.EditIndex = -1;
        showgrid();

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        showgrid();
       //totaldata();
      
    }
    protected void Button7_Click(object sender, EventArgs e)
    {



       
        string tablenm = Session["unm"].ToString();
        Response.Redirect("~/watch.aspx?data="+tablenm);
       /* string watch = ("~/image/watch.JPEG");
        string name = "watch";
        int price = 500;
        int quantity = 1;
        int total = 500;
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        string q = "insert "+tablenm+"(image,producname,price,quantity,total)values('" + watch + "','" + name + "','" + price + "','" + quantity + "','" + total + "')";
        SqlCommand cmd = new SqlCommand(q, conn);
        conn.Open();
        int i = cmd.ExecuteNonQuery();
        if (i > 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('your data is collected');", true);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Sorry !!');", true);
        }*/
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string tablenm = Session["unm"].ToString();
        Response.Redirect("~/racket.aspx?data=" + tablenm);
        //string tablenm = Request.QueryString["tnm"];
        /*string tablenm = Session["unm"].ToString();
        string recket = ("~/image/racket.JPEG");
        string name = "recket";
        int price = 50;
        int quantity = 1;
        int total = 50;
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        string q = "insert into "+tablenm+" (image,producname,price,quantity,total)values('" + recket + "','" + name + "','" + price + "','" + quantity + "','" + total + "')";
        SqlCommand cmd = new SqlCommand(q, conn);
        conn.Open();
        int i = cmd.ExecuteNonQuery();
        if (i > 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('your data is collected');", true);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Sorry !!');", true);
        }*/
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
       
       
        string tablenm = Session["unm"].ToString();
        string toys = ("~/image/toys.JPEG");
        string name = "toys";
        int price = 25;
        int quantity = 1;
        int total = 25;
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        string q = "insert into "+tablenm+" (image,producname,price,quantity,total)values('" + toys + "','" + name + "','" + price + "','" + quantity + "','" + total + "')";
        SqlCommand cmd = new SqlCommand(q, conn);
        conn.Open();
        int i = cmd.ExecuteNonQuery();
        if (i > 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('your data is collected');", true);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Sorry !!');", true);
        }
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
      
        string tablenm = Session["unm"].ToString();
        string perfumes = ("~/image/perfums.JPEG");
        string name = "perfumes";
        int price = 350;
        int quantity = 1;
        int total = 350;
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        string q = "insert into "+tablenm+"(image,producname,price,quantity,total)values('" + perfumes + "','" + name + "','" + price + "','" + quantity + "','" + total + "')";
        SqlCommand cmd = new SqlCommand(q, conn);
        conn.Open();
        int i = cmd.ExecuteNonQuery();
        if (i > 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('your data is collected');", true);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Sorry !!');", true);
        }
    }
    protected void Button5_Click(object sender, EventArgs e)
    {
      
        string tablenm = Session["unm"].ToString();
        string wallet = ("~/image/wallet.JPEG");
        string name = "wallet";
        int price = 65;
        int quantity = 1;
        int total = 65;
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        string q = "insert into "+tablenm+"(image,producname,price,quantity,total)values('" + wallet + "','" + name + "','" + price + "','" + quantity + "','" + total + "')";
        SqlCommand cmd = new SqlCommand(q, conn);
        conn.Open();
        int i = cmd.ExecuteNonQuery();
        if (i > 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('your data is collected');", true);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Sorry !!');", true);
        }
    }
    protected void Button6_Click(object sender, EventArgs e)
    {
       
        string tablenm = Session["unm"].ToString();
        string mobile = ("~/image/mobiles.JPEG");
        string name = "mobile";
        int price = 600;
        int quantity = 1;
        int total = 600;
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        string q = "insert into "+tablenm+" (image,producname,price,quantity,total)values('" + mobile + "','" + name + "','" + price + "','" + quantity + "','" + total + "')";
        SqlCommand cmd = new SqlCommand(q, conn);
        conn.Open();
        int i = cmd.ExecuteNonQuery();
        if (i > 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('your data is collected');", true);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Sorry !!');", true);
        }
    }

    protected void Button8_Click(object sender, EventArgs e)
    {
        Session.Abandon();
      
        Response.Redirect("~/loginpage.aspx");
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label tot = (Label)e.Row.FindControl("Label10");
            tot.Text = totaldata();
        }
    }
}

mobile.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="mobile.aspx.cs" Inherits="mobile" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
                <tr>
                    <td>
                      
                            <asp:Image ID="Image1" runat="server" ImageUrl="~/image/mobiles.jpeg"  />
                        <asp:Button ID="Button1" runat="server" Text="Nokia" onclick="Button1_Click1" /><br /><br />
                    </td>
               
                    <td>
                      
                            <asp:Image ID="Image2" runat="server" ImageUrl="~/mobile/samsung/s1.jpg"
                                Width="162px"  />
                            <asp:Button ID="Button3" runat="server" Text="Samsung"
                            onclick="Button1_Click" /><br /><br />
                    </td>
                </tr>
                <tr>
                    <td>
                       
                        <asp:Button ID="Button2" runat="server" Text="return to produc List"
                            onclick="Button2_Click" />
                    </td>
                       
                </tr>
               
        </table>
       <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                DataKeyNames="image,id" BackColor="White" BorderColor="#999999" BorderStyle="Solid"
                        BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical">
        <Columns>
           
            <asp:TemplateField HeaderText="image" >
            <ItemTemplate>
                <asp:ImageButton ID="Image1" runat="server" Height="60px" Width="60" />
                <asp:Label ID="Label3" runat="server" Text='<%# Eval("image") %>'></asp:Label>
            </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="id">
            <ItemTemplate>
                <asp:Label ID="Label10" runat="server" Text='<%# Eval("id") %>'></asp:Label>
            </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="name">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("name") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="price">
            <ItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Eval("price") %>'></asp:Label>
            </ItemTemplate>
            </asp:TemplateField>
           <%-- <asp:TemplateField >
                            <ItemTemplate>
                                <asp:Button ID="Button1" runat="server" Text="add" OnClick="add" CommandArgument='<%#Eval("id") %>' />
                            </ItemTemplate>
             </asp:TemplateField>--%>
            <asp:TemplateField >
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" OnClick="add" CommandArgument='<%# Eval("id") %>'>add</asp:LinkButton>
                            </ItemTemplate>
             </asp:TemplateField>
            
       
        </Columns>
                        <FooterStyle BackColor="#CCCCCC" />
                        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                        <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                        <AlternatingRowStyle BackColor="#CCCCCC" />
        </asp:GridView>
    </div>
    </form>
</body>
</html>

mobile.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class mobile : System.Web.UI.Page
{
    Image i;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/mainpage.aspx");
    }
    /*protected void Button1_Click(object sender, EventArgs e)
    {

       
        string mobile = ("~/image/mobiles.JPEG");
        string name = "mobile";
        int price = 600;
        int quantity = 1;
        int total = 600;
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        string q = "insert into shoppingcard(image,producname,price,quantity,total)values('" +mobile+ "','" + name + "','" + price + "','" + quantity + "','" + total + "')";
        SqlCommand cmd = new SqlCommand(q, conn);
        conn.Open();
        int i = cmd.ExecuteNonQuery();
        if (i > 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('your data is collected');", true);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Sorry !!');", true);
        }
    }*/
    protected void add(object sender, EventArgs e)
    {
        string id = null;
        id = ((LinkButton)sender).CommandArgument;

        string tnm1 = Session["unm"].ToString();
        string img1 = null;
        string nm1 = null;
        string pri1 = null;
        int total1 = 0;
        foreach (GridViewRow r in GridView1.Rows)
        {
            string sid = GridView1.DataKeys[r.RowIndex].Values[1].ToString();

            if (sid.Equals(id))
            {
                Label img = (Label)GridView1.Rows[r.RowIndex].FindControl("Label3");
                img1 = img.Text;
                Label nm = (Label)GridView1.Rows[r.RowIndex].FindControl("Label1");
                nm1 = nm.Text;
                Label pri = (Label)GridView1.Rows[r.RowIndex].FindControl("Label2");
                pri1 = pri.Text;
                total1 = int.Parse(pri1.ToString());
            }

        }

        int qn = 1;


        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        conn.Open();
        string q = "insert into " + tnm1 + " (image,producname,price,quantity,total)values('" + img1 + "','" + nm1 + "','" + pri1 + "','" + qn + "','" + total1 + "')";
        SqlCommand cmd = new SqlCommand(q, conn);
        int i = cmd.ExecuteNonQuery();
        if (i > 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('your data is collected');", true);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('soRRy try again');", true);
        }
    }
    protected void Button1_Click1(object sender, EventArgs e)
    {
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        conn.Open();
        string q = "select image,id,name,price from mobile where category='nokia'";
        SqlCommand cmd = new SqlCommand(q, conn);
        cmd.ExecuteNonQuery();
        SqlDataAdapter sd = new SqlDataAdapter();
        DataSet ds = new DataSet();
        sd.SelectCommand = cmd;
        sd.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();

        foreach (GridViewRow r in GridView1.Rows)
        {
            i = (Image)(GridView1.Rows[r.RowIndex].Cells[0].FindControl("Image1"));
            string s = GridView1.DataKeys[r.RowIndex].Value.ToString();
            i.ImageUrl = s.ToString();
            i.DataBind();

        }
       
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        conn.Open();
        string q = "select image,id,name,price from mobile where category='samsung'";
        SqlCommand cmd = new SqlCommand(q, conn);
        cmd.ExecuteNonQuery();
        SqlDataAdapter sd = new SqlDataAdapter();
        DataSet ds = new DataSet();
        sd.SelectCommand = cmd;
        sd.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();

        foreach (GridViewRow r in GridView1.Rows)
        {
            i = (Image)(GridView1.Rows[r.RowIndex].Cells[0].FindControl("Image1"));
            string s = GridView1.DataKeys[r.RowIndex].Value.ToString();
            i.ImageUrl = s.ToString();
            i.DataBind();

        }
    }
}

perfum.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="perfum.aspx.cs" Inherits="perfum" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
                <tr>
                    <td>
                      
                            <asp:Image ID="Image1" runat="server" ImageUrl="~/image/perfums.jpeg"  />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label1" runat="server" Text="price $350"></asp:Label>
                        <asp:Button ID="Button1" runat="server" Text="add to card"
                            onclick="Button1_Click" />
                        <asp:Button ID="Button2" runat="server" Text="back to mainpage"
                            onclick="Button2_Click1" />
                    </td>
                       
                </tr>
               
        </table>
    </div>
    </form>
</body>
</html>

perfum.aspx.cs

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.Data;

public partial class perfum : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string perfumes = ("~/image/perfums.JPEG");
        string name = "perfumes";
        int price = 350;
        int quantity = 1;
        int total = 350;
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        string q = "insert into shoppingcard(image,producname,price,quantity,total)values('" + perfumes + "','" + name + "','" + price + "','" + quantity + "','" + total + "')";
        SqlCommand cmd = new SqlCommand(q, conn);
        conn.Open();
        int i = cmd.ExecuteNonQuery();
        if (i > 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('your data is collected');", true);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Sorry !!');", true);
        }
    }
 
    protected void Button2_Click1(object sender, EventArgs e)
    {
        Response.Redirect("~/mainpage.aspx");
    }
}

watch.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="watch.aspx.cs" Inherits="watch" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
            <table>
                <tr>
                    <td>
                       <asp:Image ID="Image1" runat="server" ImageUrl="~/image/watch.jpeg"
                            Height="185px" Width="211px"  />
                        <asp:Button ID="Button3" runat="server" Text="Titan watch"
                            onclick="Button3_Click" />
                    </td>
            
                    <td>
                       <asp:Image ID="Image2" runat="server" ImageUrl="~/sonata/sonata0.jpeg"
                            Height="201px" Width="182px"  />
                        <asp:Button ID="Button4" runat="server" Text="Sonata watch"
                            onclick="Button4_Click" />
                    </td>
               
                    <td>
                       <asp:Image ID="Image3" runat="server" ImageUrl="~/fastrack/fastrack0.jpeg"
                            Height="196px" Width="182px"  />
                        <asp:Button ID="Button5" runat="server" Text="Fastrack watch"
                            onclick="Button5_Click" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <%--<asp:Button ID="Button1" runat="server" Text="add to card"
                            onclick="Button1_Click" /><br /><br />--%>
                        <asp:Button ID="Button2" runat="server" Text="return to produc List"
                            onclick="Button2_Click" />
                    </td>
                       
                </tr>
               
        </table>
        <table>
        <tr>
            <td>
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                DataKeyNames="image,id" BackColor="White" BorderColor="#999999" BorderStyle="Solid"
                        BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical">
        <Columns>
           
            <asp:TemplateField HeaderText="image" >
            <ItemTemplate>
                <asp:ImageButton ID="Image1" runat="server" Height="60px" Width="60" />
                <asp:Label ID="Label3" runat="server" Text='<%# Eval("image") %>'></asp:Label>
            </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="id">
            <ItemTemplate>
                <asp:Label ID="Label10" runat="server" Text='<%# Eval("id") %>'></asp:Label>
            </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="name">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("name") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="price">
            <ItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Eval("price") %>'></asp:Label>
            </ItemTemplate>
            </asp:TemplateField>
           <%-- <asp:TemplateField >
                            <ItemTemplate>
                                <asp:Button ID="Button1" runat="server" Text="add" OnClick="add" CommandArgument='<%#Eval("id") %>' />
                            </ItemTemplate>
             </asp:TemplateField>--%>
            <asp:TemplateField >
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" OnClick="add" CommandArgument='<%# Eval("id") %>'>add</asp:LinkButton>
                            </ItemTemplate>
             </asp:TemplateField>
            
       
        </Columns>
                        <FooterStyle BackColor="#CCCCCC" />
                        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                        <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                        <AlternatingRowStyle BackColor="#CCCCCC" />
        </asp:GridView>
      
                               
                           
            </td>
            <td>
                <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
                DataKeyNames="image,id" BackColor="White" BorderColor="#999999"
                    BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical">
                    <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
        <Columns>
           
            <asp:TemplateField HeaderText="image" >
            <ItemTemplate>
                <asp:ImageButton ID="Image1" runat="server" Height="60px" Width="60" />
                <asp:Label ID="Label4" runat="server" Text='<%#Eval("image") %>'></asp:Label>
            </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="id">
            <ItemTemplate>
                <asp:Label ID="Label10" runat="server" Text='<%# Eval("id") %>'></asp:Label>
            </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="name">
                <ItemTemplate>
                    <asp:Label ID="Label5" runat="server" Text='<%#Eval("name") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="price">
            <ItemTemplate>
                <asp:Label ID="Label6" runat="server" Text='<%#Eval("price") %>'></asp:Label>
            </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" OnClick="add1" CommandArgument='<% # Eval("id") %>'>add</asp:LinkButton>
                            </ItemTemplate>
                       
            </asp:TemplateField>
            
           
       
        </Columns>
                    <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                    <AlternatingRowStyle BackColor="#DCDCDC" />
        </asp:GridView>
       
                   
                               
                          
            <td>
                 <asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False"
                DataKeyNames="image,id" BackColor="#DEBA84" BorderColor="#DEBA84"
                     BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2">
                     <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
        <Columns>
           
            <asp:TemplateField HeaderText="image" >
            <ItemTemplate>
                <asp:ImageButton ID="Image1" runat="server" Height="60px" Width="60" />
                <asp:Label ID="Label7" runat="server" Text='<%#Eval("image") %>'></asp:Label>
            </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="id">
            <ItemTemplate>
                <asp:Label ID="Label10" runat="server" Text='<%# Eval("id") %>'></asp:Label>
            </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="name">
                <ItemTemplate>
                    <asp:Label ID="Label8" runat="server" Text='<%#Eval("name") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="price">
            <ItemTemplate>
                <asp:Label ID="Label9" runat="server" Text='<%#Eval("price") %>'></asp:Label>
            </ItemTemplate>
            </asp:TemplateField>
             <asp:TemplateField >
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" OnClick="add2" CommandArgument='<%# Eval("id") %>'>add</asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
           
       
        </Columns>
                     <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
                     <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
                     <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
                     <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
        </asp:GridView>
       
            </td>
        </tr>
       
        </table>
    </div>
    <asp:Label ID="Label11" runat="server" Text="Label"></asp:Label>
    </form>
</body>
</html>


watch.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class watch : System.Web.UI.Page
{
    Image i;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    /*protected void Button1_Click(object sender, EventArgs e)
    {
        string watch=("~/image/watch.JPEG");
        string name="watch";
        int price=500;
        int quantity=1;
        int total=500;
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        string q ="insert into shoppingcard(image,producname,price,quantity,total)values('"+watch+"','"+name+"','"+price+"','"+quantity+"','"+total+"')";
        SqlCommand cmd = new SqlCommand(q, conn);
        conn.Open();
        int i=cmd.ExecuteNonQuery();
        if (i > 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('your data is collected');", true);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Sorry !!');", true);
        }
    }*/
    protected void Button2_Click(object sender, EventArgs e)
    {   string tnm1 = Request.QueryString["data"];
       // Response.Redirect("~/mainpage.aspx?td="+tnm1);
    Response.Redirect("~/mainpage.aspx");
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
       
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        conn.Open();
        string q = "select * from titan";
        SqlCommand cmd = new SqlCommand(q, conn);
        cmd.ExecuteNonQuery();
        SqlDataAdapter sd = new SqlDataAdapter();
        DataSet ds = new DataSet();
        sd.SelectCommand = cmd;
        sd.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();

        foreach (GridViewRow r in GridView1.Rows)
        {
            i = (Image)(GridView1.Rows[r.RowIndex].Cells[0].FindControl("Image1"));
            string s = GridView1.DataKeys[r.RowIndex].Value.ToString();
            i.ImageUrl = s.ToString();
            i.DataBind();

        }
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        conn.Open();
        string q = "select * from sonata";
        SqlCommand cmd = new SqlCommand(q, conn);
        cmd.ExecuteNonQuery();
        SqlDataAdapter sd = new SqlDataAdapter();
        DataSet ds = new DataSet();
        sd.SelectCommand = cmd;
        sd.Fill(ds);
        GridView2.DataSource = ds;
        GridView2.DataBind();

        foreach (GridViewRow r in GridView2.Rows)
        {
            i = (Image)(GridView2.Rows[r.RowIndex].Cells[0].FindControl("Image1"));
           
            string s = GridView2.DataKeys[r.RowIndex].Value.ToString();
            i.ImageUrl = s.ToString();
            i.DataBind();

        }
    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        conn.Open();
        string q = "select * from fastrack";
        SqlCommand cmd = new SqlCommand(q, conn);
        cmd.ExecuteNonQuery();
        SqlDataAdapter sd = new SqlDataAdapter();
        DataSet ds = new DataSet();
        sd.SelectCommand = cmd;
        sd.Fill(ds);
        GridView3.DataSource = ds;
        GridView3.DataBind();

        foreach (GridViewRow r in GridView3.Rows)
        {
            i = (Image)(GridView3.Rows[r.RowIndex].Cells[0].FindControl("Image1"));

            string s = GridView3.DataKeys[r.RowIndex].Value.ToString();
            i.ImageUrl = s.ToString();
            i.DataBind();
        }
    }

    protected void add(object sender, EventArgs e)
    {
        string id = null;
        id = ((LinkButton)sender).CommandArgument;
        Label11.Text = id.ToString();
        string tnm1 = Session["unm"].ToString();
        string img1=null;
        string nm1=null;
        string pri1=null;
        int total1=0;
        foreach (GridViewRow r in GridView1.Rows)
        {
            string sid = GridView1.DataKeys[r.RowIndex].Values[1].ToString();
            Label11.Text = sid;
           if (sid.Equals(id))
           {
                Label img = (Label)GridView1.Rows[r.RowIndex].FindControl("Label3");
                img1 = img.Text;
                Label nm = (Label)GridView1.Rows[r.RowIndex].FindControl("Label1");
                nm1 = nm.Text;
                Label pri = (Label)GridView1.Rows[r.RowIndex].FindControl("Label2");
                pri1 = pri.Text;
                total1 = int.Parse(pri1.ToString());
            }
                  
        }
       
        int qn=1;

       
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        conn.Open();
        string q = "insert into "+tnm1+" (image,producname,price,quantity,total)values('" + img1 + "','" + nm1+ "','" + pri1 + "','" + qn + "','"+total1+"')";
        SqlCommand cmd = new SqlCommand(q, conn);
        int i=cmd.ExecuteNonQuery();
        if (i > 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('your data is collected');", true);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('soRRy try again');", true);
        }
    }
    protected void add1(object sender, EventArgs e)
    {
        string img1 = null;
        string nm1 = null;
        string pri1 = null;
        int total1 = 0;
        string tnm1 = Request.QueryString["data"];
        string id = null;
        id = ((LinkButton)sender).CommandArgument;
        foreach (GridViewRow r in GridView2.Rows)
        {

            string sid = GridView2.DataKeys[r.RowIndex].Values[1].ToString();
            if(sid.Equals(id))
            {
                Label img = (Label)GridView2.Rows[r.RowIndex].FindControl("Label4");
                img1 = img.Text;
                Label nm = (Label)GridView2.Rows[r.RowIndex].FindControl("Label5");
                nm1 = nm.Text;
                Label pri = (Label)GridView2.Rows[r.RowIndex].FindControl("Label6");
                pri1 = pri.Text;
                total1 = int.Parse(pri1.ToString());
            }
        }
        int qn = 1;

       
        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        conn.Open();
        string q = "insert into "+tnm1+"(image,producname,price,quantity,total)values('" + img1 + "','" + nm1 + "','" + pri1 + "','" + qn + "','"+total1+"')";
        SqlCommand cmd = new SqlCommand(q, conn);
        int i = cmd.ExecuteNonQuery();
        if (i > 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('your data is collected');", true);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('soRRy try again');", true);
        }
    }

    protected void add2(object sender, EventArgs e)
    {
        string img1 = null;
        string nm1 = null;
        string pri1 = null;
        int total1 = 0;
        string tnm1 = Request.QueryString["data"];
        string id = null;
        id = ((LinkButton)sender).CommandArgument;
        foreach (GridViewRow r in GridView3.Rows)
        {

            string sid = GridView3.DataKeys[r.RowIndex].Values[1].ToString();
            if (sid.Equals(id))
            {
                Label img = (Label)GridView3.Rows[r.RowIndex].FindControl("Label7");
                img1 = img.Text;
                Label nm = (Label)GridView3.Rows[r.RowIndex].FindControl("Label8");
                nm1 = nm.Text;
                Label pri = (Label)GridView3.Rows[r.RowIndex].FindControl("Label9");
                pri1 = pri.Text;
                total1 = int.Parse(pri1.ToString());
            }
        }
        int qn = 1;


        string con = @"Data Source=SQLDB;User ID=Demod;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        conn.Open();
        string q = "insert into " + tnm1 + "(image,producname,price,quantity,total)values('" + img1 + "','" + nm1 + "','" + pri1 + "','" + qn + "','" + total1 + "')";
        SqlCommand cmd = new SqlCommand(q, conn);
        int i = cmd.ExecuteNonQuery();
        if (i > 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('your data is collected');", true);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('soRRy try again');", true);
        }
    }
}

0 comments :