Create
an empty web site with a sample SQL Server database attached. Add a web
form to the web site and drag a “gridView” control on the new form.
Select
the arrow on the right of the GridView control and select “New
Datasource” in the dropdown menu by “Choose Datasource... “.
Choose “SQL Database” and click “OK”.
Choose the name of the database you created from the dropdown menu and click “Next”.
Make sure “Yes” is checked in the check box and a connection string name has been filled in and click “Next”.
Accept the defaults and click “Advanced”.
Check “Generate Update, Insert and Delete Statements”. Check “Use optimistic concurrency”. Click “OK”. Click “Next”.
Click “Test Query”. Click “Finished”.
Enable paging by clicking on checkbox labeled “Paging”
Enter 5 in the “PageSize” property of your gridView control.
Press
F5 to start the debugging session to see if your gridView shows in the
browser with the data from your database. Assuming that you have more
than 5 rows in your database, you should notice that there are page
number links at the bottom of your gridView control.
You can change the “PagerSetting” for your gridView properties to enable non-numeric page navigation in the “Mode” property.
The text of the previous, next, first and last can be changed from HTML codes to plain text.
Enable sorting by clicking on checkbox labeled “Sorting”.
Press
F5 to start the debugging session to see that the first row of your
gridView has the titles underlined. Click on the underlined text to sort
the rows in either ascending or descending.
You can download the complete program here.
No comments:
Post a Comment