asp.net 2.0 build Shopping cart and payment System II

Source: Internet
Author: User

Related articles:

asp.net 2.0 build one of the shopping carts and payment systems

In this article, we will explore the GridView through a simple online store demo program, and begin to analyze a method of generating the datasource of the GridView, and then continue to use that data to create a fully functional shopping interface. Note that the DataSource in this demo program is free to create.

First, Introduction

In the first article, we discussed what a GridView is and how to use it, including how the actual data is bound to it. In this article, we will analyze the source of these data more closely and how to use it with the GridView to implement a simple shopping interface.

Where does the data come from?

Fundamentally, this problem depends on what you are doing. It can come from a static XML file, a dynamic XML feed, a database, and perhaps it is freely created. However, you should ensure that you are satisfied: if there is data, you can ensure that it can "import" into a GridView. In this article, this part of the data is created freely each time the application is restarted.

The datasource used to populate the two GridView is a DataTable. It is built using DataColumns and DataRows. In this main class file there is a function called "Createproductdt", which shows how the DataTable was initially created. Here is the complete implementation of the function:

Private DataTable Createproductdt ()
{
DataTable dtproducts = new DataTable ();
DataColumn productcolumn = new DataColumn ();
Productcolumn.datatype = System.Type.GetType ("System.Int32");
Productcolumn.columnname = "id";
Productcolumn.unique = true;
DtProducts.Columns.Add (Productcolumn);
Productcolumn = new DataColumn ();
Productcolumn.datatype = System.Type.GetType ("System.String");
Productcolumn.columnname = "thumb";
DtProducts.Columns.Add (Productcolumn);
Productcolumn = new DataColumn ();
Productcolumn.datatype = System.Type.GetType ("System.String");
Productcolumn.columnname = "name";
DtProducts.Columns.Add (Productcolumn);
Productcolumn = new DataColumn ();
Productcolumn.datatype = System.Type.GetType ("System.Double");
Productcolumn.columnname = "Price";
DtProducts.Columns.Add (Productcolumn);
Productcolumn = new DataColumn ();
Productcolumn.datatype = SystEm. Type.GetType ("System.Int32");
Productcolumn.columnname = "Quantity";
DtProducts.Columns.Add (Productcolumn);  
//make "ID" the primary key
datacolumn[] Pkcolumns = new datacolumn[1];
Pkcolumns[0] = dtproducts.columns["id"];
Dtproducts.primarykey = pkcolumns;
return dtproducts;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.