Yesterday I followed the book through Ch7 and managed to complete the exercises. Today I tried to apply some of what I thought I had learned to a web page for a Walking Group. I decided to create a page like the final Fixtures.aspx page, with a selectable GridView control listing walk activities and a DetailsView control to display information for the selected walk.
I prepared an Access database beforehand and added it into App_Data. I added the GridView and DetailsView controls to the page and linked them to the database, but I couldn't get it to work as I wanted. I could only get one record to display in the GridView.
After much fiddling, and re-reading the book, I decided to start from Fixtures.aspx and develop it how I wanted, which is to have 5 or 6 activities listed, with paging controls. But I can't get the GridView to behave, and I can't work out what it is that I've done to the working Fixtures.aspx page.
Here is my code:
Code:
<%@ Page Language="VB" MasterPageFile="~/site.master" AutoEventWireup="false" CodeFile="Fixtures.aspx.vb" Inherits="Fixtures" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:gridview ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="EventName,StartDate"
DataSourceID="AccessDataSource1" EmptyDataText="There are no data records to display." AllowPaging="True">
<columns>
<asp:commandfield ShowSelectButton="True" />
<asp:boundfield DataField="EventName" HeaderText="EventName" SortExpression="EventName" />
<asp:boundfield DataField="StartDate" HeaderText="StartDate" SortExpression="StartDate" />
</columns>
<pagersettings FirstPageText="Oldest" LastPageText="Newest" Mode="NextPreviousFirstLast"
Position="TopAndBottom" />
</asp:gridview>
<asp:accessdatasource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/EventManagement1.mdb"
SelectCommand="SELECT [EventName], [StartDate], [EventID] FROM [Events] ORDER BY [StartDate]">
</asp:accessdatasource>
<asp:detailsview ID="DetailsView1" runat="server" DataSourceID="AccessDataSource2" Height="50px"
Width="340px" AutoGenerateRows="False" DataKeyNames="EventName,StartDate,EventDescription,StartTime,EmployeeID,Travel,WalkDistance,Location">
<fields>
<asp:boundfield DataField="EventName" HeaderText="EventName" SortExpression="EventName" />
<asp:boundfield DataField="StartDate" HeaderText="StartDate" SortExpression="StartDate" />
<asp:boundfield DataField="StartTime" HeaderText="StartTime" SortExpression="StartTime" />
<asp:boundfield DataField="EventDescription" HeaderText="EventDescription" SortExpression="EventDescription" />
<asp:boundfield DataField="WalkDistance" HeaderText="WalkDistance" SortExpression="WalkDistance" />
<asp:boundfield DataField="Location" HeaderText="Location" SortExpression="Location" />
<asp:boundfield DataField="Travel" HeaderText="Travel" SortExpression="Travel" />
<asp:boundfield DataField="EmployeeID" HeaderText="EmployeeID" SortExpression="EmployeeID" />
</fields>
</asp:detailsview>
<asp:accessdatasource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/EventManagement1.mdb"
SelectCommand="SELECT [EventID], [EventName], [Location], [StartDate], [StartTime], [EventDescription], [EmployeeID], [Travel], [WalkDistance] FROM [Events] WHERE ([EventID] = ?)">
<selectparameters>
<asp:controlparameter ControlID="GridView1" DefaultValue="1" Name="EventID" PropertyName="SelectedValue"
Type="Int32" />
</selectparameters>
</asp:accessdatasource>
</asp:Content>
Richard
Rugeley, UK
WinXP Pro SP2
VBW Express