Detailed usage of DataGrid paging in vs.net beta 2

Source: Internet
Author: User

Use DataGrid paging in Beta 2

Note:

1. This articleArticleIt is only applicable to beginners of vs.net, especially those who are not familiar with the vs.net environment.

2. required environment: Win2000, SQL Server2000, vs.net beta2

Steps:

1. Open vs. Net beta 2;

2. Create a C # ASP. NET web applicationProgramProject;

3. Drag from the Toolbox> data pageSqldataadapter
To the web form design window;

TIPS:CTRL-ALT-XYou can quickly switch to the Toolbox interface;

4. The data configurator Configuration Wizard Page appears as follows:

5. Click Next and we will start configuring the connection to the database.

Database connection, we will create a connection, click Create connection, here we will connect to SQL
Server

The built-in northwind database, and extract some data from the products table, as shown below;

Note: The following describes how to establish a database connection;

6. After a database connection is established, we will read the data here for simplicity, we

Read Only the values of several fields in the products table;

Note: because we do not consider modification or deletion, we will remove the insert,

Update and delete statements to update the data source options;

Note: The following figure uses the Query Builder to generate SQL statements;

Note: You can also manually enter SQL statements without having to bother with the preceding steps;

Note: Click Next, confirm, and click Finish to complete the configuration of sqldataadapter;

Click Finish to view the Web
In the lower part of the form design window, vs. Net creates

SqldataadapterAndSqlconnection
An area of the object;

SelectSqldataadapter1
Right-click to viewCode;

You can see the Code created by vs.net for the previous step;

7. SelectSqldataadapter1 object. At this time, you can see in the lower right corner of the property page:

Configure the data adapter (c)..., generate the dataset (g)..., preview the data (p )...

Click Generate dataset;

Note: The following window appears at this time. Use the default settings. Click OK to generate the dataset: dataset11;

8. Drag a dataview object from the Toolbox> data page to the design view;

9. Select the dataview1 object and set its Attribute Table to the products of dataset1, as shown in;

10. Drag a DataGrid object from the Toolbox> Web form to the design view;

11. Set the datasource attribute of the datagrid1 object to dataview1;

12. Set the allowpaging attribute of the datagrid1 object to true. The pagesize value is the number of records displayed on each page. You can also modify the value;

13. Select datagrid1. The following connections are available on the attribute page:

14. CLICK: Property generator, which appears. In paging settings, we change the mode to page number (different modes, and the code written on different pages later );

15. Click "Apply format automatically". You can modify the format of datagrid1, which is a matter of appearance. You can choose one based on your interests;

16. Below we need to write some code;

For example, click the red area, and the selected object is webform1. On the property page, click the blue area button, which is the lightning button, go to the event page of this object,

17. Double-click the webform1 event load, which is a blue-dark place. vs.net automatically adds the load event function of webform1;

For example, add the Code in the following figure;

In the same way, add the pageindexchanged event of dataview1 and add the following code;

At this point, our work has been completed. Press F5 to compile and you will see the result.

Tip: I do not know if it is a bug of beta2. In the code page, enter the event as follows. It will not add this event to the event list, but this event function will appear. At this time, you need to add it to the event list by yourself, that is, add the downstream code:

On the code editing page, select a function to enter and quickly jump to the specified function. Without this function, it creates the function, however, the event corresponding to this function is not added to the event. At this time, we need to add the code in the blue highlighted area.

Reference Source:

1. http://www.aspnextgen.com

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.