C#
  Home arrow C# arrow Page 3 - Creating an Online Shopping Cart and PayPa...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

Creating an Online Shopping Cart and PayPal System
By: Tann San
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 28
    2006-06-13

    Table of Contents:
  • Creating an Online Shopping Cart and PayPal System
  • The GridView
  • The Page Declaration
  • An Important Function

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating an Online Shopping Cart and PayPal System - The Page Declaration


    (Page 3 of 4 )

      <%@ page inherits="shop.site" src="cs/site.aspx.cs" %>

    The page declaration simply tells our page what namespace and class it belongs to; in this case our namespace is "shop" and our class is "site".  There is an additional property defined called "src" which points to the plain text .cs file that contains the site class.

    I normally have my classes contained in external .cs files as opposed to manually compiling them to .dll files during development. I do most of my coding with a simple text editor (Crimson Editor), so compiling with the command line after each change would be pretty time consuming.  Having the files as external .cs files means that each time the page is viewed after a change has been made, it will automatically get recompiled into a new cached dll by the server. If I was using Visual Studio or one of the free Express IDEs, I'd use pre-compiled dlls during development, because it would then be a simple case of hitting Build to generate them. I do build the classes into pre-compiled dlls once I have finished working on them, but during development I prefer to spend my time coding, not compiling.  I could write a batch file to do the command line compilation via a simple double click, but I'm extremely lazy and never got into the habit of doing this.

    Binding Data

      <asp:GridView
         id="gvBasket"
         AutoGenerateColumns="false"
         ShowHeader="True"
         ShowFooter="True"
         DataKeyNames="id"     
         OnRowDataBound="gvBasket_RowDataBound"
         runat="server">     
         <Columns>
            <asp:ImageField DataImageurlField="thumb" alternatetext="Product Thumbnail" readonly="true" />
            <asp:TemplateField HeaderText="Item">
               <ItemTemplate>
                  <h3><asp:Literal id="litItemName" runat="server" /></h3>
               </ItemTemplate>
               <FooterTemplate>
                  <a href="delivery-costs.aspx" title="View the list of delivery charges">Delivery Charges</a>
                  <br /><hr />
                  <b>Total</b>
               </FooterTemplate>
            </asp:TemplateField>
         </Columns>
      </asp:GridView>

    If you take a closer look at both of the GridViews you will notice that they both have AutoGenerateColumns set to false. Without this line, or if it was set to true, our columns would be created for us when we bind the DataSource. By turning this feature off we can define our own columns using the "Columns" sub tag.  Inside that we can create a number of different type columns. In this demonstration we have used the ImageField and TemplateField column types.  The ImageField column takes an image path as its value via the DataImageUrlField property and then displays that image inside its own column when rendered to the page. 

    The TemplateField is the real gem column. It allows you to define a HeaderTemplate, an ItemTemplate and a FooterTemplate among others. These three tags let you put any content you want into these areas. The HeaderTemplate and FooterTemplate both refer to that column's header and footer, and the ItemTemplate refers to the body content that is displayed in that column for each row.

    If you look at the basket GridView you will see that we've used the ItemTemplate to show the name, price and quantity of each item in the basket, and then in the FooterTemplate we are displaying both the delivery charges and the totals.  The above snippet just shows the "name" column and its footer; to see the full implementation look in the default.aspx source file.  Because the headers for each column are just going to be static text we skipped using the HeaderTemplate and instead opted for the HeaderText property of the TemplateField.  To show the header and footer of a GridView you must set the ShowHeader and ShowFooter properties to True on the GridView.

    Another reason the ItemTemplate is great to use is that you can put other HTML and .net tags inside it. In the demonstration there are several different types including <input>, <br />, <hr />, <asp:Literal> and <a>. The only downside to putting these inside an ItemTemplate tag is that you have to do a little more work to pre-populate them, but luckily it isn't much.  The first step is to set the RowDataBound event on the GridView. You assign a function to this that will get called each time a row is created after we bind our DataSource. You can see this in the basket GridView properties:

      OnRowDataBound="gvBasket_RowDataBound"

    The equivalent function for the product GridView is simpler but it only shows how to populate the ItemTemplate and not the Header or Footer templates. 

    More C# Articles
    More By Tann San


       · Hey, I'm open to...
       · for some reason it wont work on my server do i have to have an asp server?
       · Hiya, you need to make sure you have the Microsoft .net Framework v1 and v2...
       · I am wondering if you could show an example of how to calculate the delivery costs...
     

    C# ARTICLES

    - C# and XML
    - Pointers and Arrays in C#
    - C# 3.0 Extension Methods
    - Overloading Operators in C#
    - Iterators and Nullable Types
    - Patterns and Iterators in C#
    - C# Exceptions
    - Methods in C#
    - Delegates and Events in C#
    - Advanced C#
    - Working with Regular Expressions in C#
    - Sending Simple E-Mail in C#
    - Building C# Comparable Objects: IComparable ...
    - Color Transformation Applications in C# GDI+...
    - Performing Color Transformation Operations i...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT