RAD Studio for Microsoft .NET
ContentsIndex
PreviousUpNext
Building an ASP.NET Application with Database Controls, Part 2

This example shows further development of a Web page containing a GridView control and database control. The steps add more capability to the GridView control, including editing. This example illustrates:

  • Using the Smart Tasks window.
  • Changing the configuration of a data source.
  • Running the application in a browser.

To add editing to the GridView control

  1. Open or resume development with the project described in Building an ASP.NET Database Application 1. At the end of that phase, the Design pane showed a GridView control and a SqlDataSource control in the Design pane of the Code Editor.
  2. To enable GridView display features, open the GridView component's Smart Tasks window by clicking on the arrow near the upper right corner of the GridView control. Check Enable Sorting, Enable Selection and Enable Paging. The design time representation of the GridView gets updated.
  3. To view the page in a Web browser, right-click the Code Editor and click View In Browser on the context menu. Paging, sorting and selecting are now supported by this grid. You can sort each column by clicking the column name at the top of the column. Select doesn’t appear to work, because the format of the GridView doesn’t highlight selected rows. Paging is not enabled if the data is less than one page.
  4. Return to the Designer pane of the Code Editor. Open the GridView Smart Tasks window and click Auto Format to display the Auto Format dialog. Choose Classic. The webform1.aspx file's description of the asp:GridView component now has style properties that were modified by selecting Classic on the Auto Format dialog.
  5. At this point, row selection is enabled. To enable row editing, you may need to reconfigure the connection. On the GridView Smart Tasks window, click Configure Data Source. Click Next in the Choose Your Data Connection dialog. Click the Advanced button in the Configure the Select Statement dialog. On the Advanced SQL Generation Options dialog, check Generate INSERT, UPDATE, and DELETE statements. Click OK to close the Advanced SQL Generation Options dialog.
    Note: You cannot use the Advanced SQL Generation Options
    dialog if you chose to generate your own SQL statements in the Configure the Select Statement dialog.
  6. Click Next then Finish in the Configure the Select Statement dialog to exit the wizard.
  7. The GridView Smart Tasks window now contains Enable Editing and Enable Deleting check boxes. Check both of these. The GridView control on the Design pane now shows Edit and Delete links.
  8. To view the page in a Web browser, right-click the Code Editor and click View In Browser on the context menu. The Edit, Delete and Select links should work for each row.
This completes Part 2 of the example.

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!