In Tip#64, we showed you how to convert a GridView's bound fields into template fields.  In this tip, we will show you how to quickly create a GridView that is hooked up to a SQL table. 

Typically, if you want a GridView then you need to add it to the page, and then add the datasource and hook the two up through a wizard.  But here's a much quicker way to create and hookup the two.

  1. First, if you don't have a connection to your database, then you will need to add it in the Server Explorer (right side of Figure 1). 
  2. Once that is done, you can expand the Tables node in your connection and find the table you want your GridView to be hooked up to initially. 

    DragDrop

    Figure 1 (click to enlarge)

  3. Finally, you drag and drop the selected table onto the webform and that's it!  You just created a GridView that is hooked up to your table in just three steps or less. 

DragDropComplete

Figure 2

From here on, you can fine tune the GridView and datasource to meet your needs.

Roger Wong
SDET | Visual Web Developer