Introducing ASP.NET 2.0: GridView Control - Save and Run
(Page 3 of 5 )
Save and run the project by pressing the F5 key. Visual Web Developer Web Server automatically starts, and you will view the output in a new Internet Explorer Window (See Figure 8).

Figure 8
The above procedure doesn't require any coding. Visual Studio 2005 automatically does the required coding in the background. I have reproduced a snippet from the code to help give you a better understanding of what it is doing (See Listing 1).
Listing 1
<asp:GridView AutoGenerateColumns="False" DataKeyNames="Name,Price,Publisher" DataMember="DefaultView"
DataSourceID="AccessDataSource1" ID="GridView1" runat="server">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name"></asp:BoundField>
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price"></asp:BoundField>
<asp:BoundField DataField="Publisher" HeaderText="Publisher" SortExpression="Publisher">
</asp:BoundField>
</Columns>
</asp:GridView>
<asp:AccessDataSource DataFile="F:\CODEPUT_NEW\CODE\App_Data\Books.mdb" ID="AccessDataSource1"
runat="server" SelectCommand="SELECT * FROM [books]"></asp:AccessDataSource>
The path given along with the DataFile property may be different from the one given above while you are working with this lab. As you can see, very little code is required for populating a GridView control, and Visual Studio 2005 does the entire job for us.
Let us now discuss some of the advanced functionalities which can be performed using the GridView control.
Next: Adding Paging Functionality to GridView >>
More ASP.NET Articles
More By Anand Narayanaswamy