oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Displaying Master-Details Relationships in ASP.NET 2.0
Pages: 1, 2, 3, 4, 5

That's it! To enable the GridView to support paging, sorting, and selection, check the respective checkboxes in its Smart tag as shown in Figure 6.

Figure 6. Enabling the GridView to support paging, sorting, and selection

The steps outlined above use the wizard in Visual Studio 2005 to configure the data source control for the GridView control. Alternatively, you can also manually copy the following code into the Source View of default.aspx:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
AllowSorting="True" AutoGenerateColumns="False"  
DataKeyNames="au_id" DataSourceID="SqlDataSource1">
        <asp:CommandField ShowSelectButton="True" />
        <asp:BoundField DataField="au_id" HeaderText="au_id" 
           ReadOnly="True" SortExpression="au_id" />
        <asp:BoundField DataField="au_lname" HeaderText="au_lname" 
           SortExpression="au_lname" />
        <asp:BoundField DataField="au_fname" HeaderText="au_fname" 
           SortExpression="au_fname" />
        <asp:BoundField DataField="phone" HeaderText="phone" 
           SortExpression="phone" />
        <asp:BoundField DataField="address" HeaderText="address" 
           SortExpression="address" />
        <asp:BoundField DataField="city" HeaderText="city" 
           SortExpression="city" />
        <asp:BoundField DataField="state" HeaderText="state" 
           SortExpression="state" />
        <asp:BoundField DataField="zip" HeaderText="zip" 
           SortExpression="zip" />
        <asp:CheckBoxField DataField="contract" HeaderText="contract" 
           SortExpression="contract" />

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
   ConnectionString="<%$ ConnectionStrings:pubsConnectionString %>"
   SelectCommand="SELECT * FROM [authors]">

Below is the connection string in web.config:

      <add name="pubsConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=pubs;Integrated Security=True"
         providerName="System.Data.SqlClient" />

Finally, beautify the GridView control by applying the Sand & Sky scheme to the GridView control. (using the Auto Format… link in the Smart tag). Press F5 to debug the application. Figure 7 shows that you can select a record by clicking the Select link.

Figure 7. Viewing and selecting records

Pages: 1, 2, 3, 4, 5

Next Pagearrow