Beta 2 uses DataGrid page
Description:
1, this article is only suitable for beginners vs.net, especially for the VS.NET environment is not very familiar.
2, the environment you need: Win2000, SQL Server2000, VS.NET Beta2
step:
Open vs.net beta 2;
2. Create a C # ASP.NET web application project;
3. Drag SqlDataAdapter to the Web Form Design window from the toolbox -> data page;
Tip: Ctrl-alt-x can quickly switch to the tool box interface;
4. The Data Configuration Wizard interface appears, as follows:
5, click Next, we will start configuring the connection with the database, because we have not configured before
Database connection, we will create new connections, click New Connection, here we will connect SQL Server
The own Northwind database, and extract some data from the Products table, as follows;
Description: The database connection is established below;
6. After establishing a database, we will read the data, here is simple, we
Only the value of several fields of the Products table;
Explanation: Since we don't consider modifying, deleting problems, here we will remove INSERT in advanced options,
Update and delete statements to update the options for the data source;
Description: The following is a picture of the SQL statement to generate a SQL statement using the query generator;
Explanation, you can also use it if you don't have to cumbersome you can manually;
Description: Click Next, finally confirmation, click Finish, complete the configuration of SqlDataAdapter;
After the click is complete, you can see that below the Web Form Design window, VS.NET creates an included
SqlDataAdapter and a area of the SqlConnection object;
Select SqlDataAdapter1 Click Right-click to view the code;
You can see the code that vs.net is established by the steps;
7. Select SqlDataAdapter1 object, then you can see at the lower right corner of the property page:
Configure data adapter (c) .... Generate a data set (G) ..., preview data (P) ...
Click to generate a data set;
Description: This time you will appear, use the default settings, click Confirm that will generate a dataset: DataSet11;
8. Drag a DataView object from the toolbox -> data page to the design view;
9, select the DataView1 object, and set its property Table property to DataSet1's Products, as shown below;
10. Drag a DataGrid object from the Toolbox -> Web Form to the design view;
11. Set the DataSource attribute of the DataGrid1 object: DataView1;
12. Set the allowpaging property of the DataGrid1 object to: true, PageSize is the number of records displayed per page, or modify;
13. Select DataGrid1, in the property page, there is a connection:
14. Click: Attribute Builder, appears in the figure, in paging settings, our modification mode is: page number (different mode, the code written by our page is also different);
15. Click on the automatic set format, you can modify the format of DataGrid1, these are the appearance of the problem, you can choose one according to your hobby; 16, below we need to write some code;
As shown below: Mouse click red area, this is the object after displaying the selected object is: WebForm1, then at the property page, click the button of the blue area, is the lightning button, enter this object's event page,
17. Double-click the mouse on the WebForm1 event load, which is the dark blue place below, and vs.net automatically adds WebForm1's LOAD event function;
As shown below, add the code in the following figure;
The same method, add the PageIndexchange event of DataView1, and add the following code;
At this point, our work has been completed, press F5 buttons, and you can see the result.
Tip: I don't know if it is a bug of Beta2. On the code page, if you enter the event, it will not add this event in the event list, but this event function, this time you need to add it to an event list In the middle, it is to increase the downlink code:
In the above picture, in the code editing page, select a function to enter, it will quickly jump to the specified function. If this function, it creates this function, but lacks the events corresponding to this function to the event, this time we You need to add the code of the blue highlight area with an additional picture.
Reference Source:
1, http://www.aspnextgen.com