Sunday, July 1, 2012

For common MS-WORD Shortcut keysCode for the Shopping cart without having database its basically for small applications where you have to be fast and you have small no. of items to be stored
source code

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

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

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Web Cart </title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;<asp:Label ID="Label1" runat="server" Height="21px" Text="Demo for Students By YASH"
            Width="288px"></asp:Label><br />
        <table>
            <tr>
                <td style="width: 100px">
                    <asp:DropDownList ID="DropDownList1" runat="server" Width="198px">
                        <asp:ListItem Value="25.50">LUX</asp:ListItem>
                        <asp:ListItem Value="45.60">MEDIMAX</asp:ListItem>
                        <asp:ListItem Value="34.75">CIBACA</asp:ListItem>
                        <asp:ListItem Value="43.50">CLOSEUP</asp:ListItem>
                    </asp:DropDownList></td>
                <td style="width: 100px">
                    <asp:Button ID="btnAdd" runat="server" Text="Add to Cart" OnClick="btnAdd_Click" /></td>
            </tr>
            <tr>
                <td colspan="2">
                </td>
            </tr>
            <tr>
                <td colspan="2" style="height: 176px">
        <asp:GridView ID="GridView1"
  ShowFooter="true" DataKeyNames="ProductId"
  AutoGenerateColumns="false" runat="server">
<Columns>
<asp:BoundField DataField="Productid" HeaderText="Product Id" />
<asp:BoundField DataField="ProductName" FooterText="Total" HeaderText="Product Name" />
<asp:TemplateField HeaderText="Unit Price" FooterStyle-Font-Bold="True">
<ItemTemplate>
  <%# GetUnitPrice(decimal.Parse(Eval("UnitPrice").ToString())).ToString("N2") %>
</ItemTemplate>
<FooterTemplate>
  <%# GetTotal().ToString("N2") %>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
                </td>
            </tr>
        </table>

    </div>
    </form>
</body>
</html>



C# code

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

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

    }
    private void DataTable()
    {
        DataTable MyDT = new DataTable();
        DataRow MyRow;
        if (ViewState["DataTable"] == null)
        {
            MyDT.Columns.Add("Productid", System.Type.GetType("System.Int32"));
            MyDT.Columns.Add("ProductName");
            MyDT.Columns.Add("UnitPrice", System.Type.GetType("System.Decimal"));
            MyRow = MyDT.NewRow();
            MyRow[0] = MyDT.Rows.Count + 1;
            MyRow[1] = DropDownList1.SelectedItem.Text;
            MyRow[2] = DropDownList1.SelectedItem.Value;
            MyDT.Rows.Add(MyRow);
        }
        else
        {
            MyDT = (DataTable)ViewState["DataTable"];
            MyRow = MyDT.NewRow();
            MyRow[0] = MyDT.Rows.Count + 1;
            MyRow[1] = DropDownList1.SelectedItem.Text;
            MyRow[2] = DropDownList1.SelectedItem.Value;
            MyDT.Rows.Add(MyRow);
        }
        ViewState["DataTable"] = MyDT;
        GridView1.DataSource = MyDT;
        GridView1.DataBind();
    }

    protected decimal TotalUnitPrice;
    protected decimal GetUnitPrice(decimal Price)
    {
        TotalUnitPrice += Price;
        return Price;
    }
    protected decimal GetTotal()
    {
        return TotalUnitPrice;
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        DataTable();
    }
}



For common Ms-Word shortcut keys

Www.skvzm.blogspot.com

No comments:

Post a Comment