Datasheet
Type=”DateTime” />
<asp:Parameter DefaultValue=”0” Name=”MaxRows” Type=”Int32” />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name=”EventId” Type=”Int64” />
</DeleteParameters>
</asp:ObjectDataSource>
Notice that the SelectParameters and the DeleteParameters are set to specify the data passed to the
GetDiaryEventsByDate() method used to pull back the data, and the DeleteEvent() method is used
to delete diary events.
A
GridView control is hooked to the ObjectDataSource in the code above:
<asp:GridView ID=”eventsGridView” runat=”server”
AutoGenerateColumns=”False” CellPadding=”4”
DataSourceID=”eventsObjectDataSource” ForeColor=”#333333”
GridLines=”None” Height=”1px”
PageSize=”5” Style=”z-index: 108; left: 78px; position: absolute; top:
357px”
Width=”542px” DataKeyNames=”EventId”>
<FooterStyle BackColor=”#5D7B9D” Font-Bold=”True” ForeColor=”White” />
<RowStyle BackColor=”#F7F6F3” ForeColor=”#333333” />
<Columns>
<asp:HyperLinkField DataNavigateUrlFields=”EventId” Text=”Edit”
DataNavigateUrlFormatString=”~/SecureDiary/EditEvent.aspx?EventId={0}” />
<asp:CommandField ShowDeleteButton=”True” />
<asp:BoundField DataField=”EventName” HeaderText=”Event” />
<asp:BoundField DataField=”EventDescription”
HeaderText=”Description” />
</Columns>
<PagerStyle BackColor=”#284775” ForeColor=”White”
HorizontalAlign=”Center” />
<SelectedRowStyle BackColor=”#E2DED6” Font-Bold=”True”
ForeColor=”#333333” />
<HeaderStyle BackColor=”#5D7B9D” Font-Bold=”True” ForeColor=”White” />
<EditRowStyle BackColor=”#999999” />
<AlternatingRowStyle BackColor=”White” ForeColor=”#284775” />
</asp:GridView>
Again, the AutoGenerateColumns parameter is set to False, and the columns are specified as follows:
<Columns>
<asp:HyperLinkField DataNavigateUrlFields=”EventId” Text=”Edit”
DataNavigateUrlFormatString=”~/SecureDiary/EditEvent.aspx?EventId={0}” />
<asp:CommandField ShowDeleteButton=”True” />
<asp:BoundField DataField=”EventName” HeaderText=”Event” />
<asp:BoundField DataField=”EventDescription”
HeaderText=”Description” />
</Columns>
Notice the hyperlink and field that when clicked will take the user to the EditEvent.aspx page, and the
URL contains data passed to the
EventId in the URL by way of the EventId querystring parameter. It’s set
to be
{0}, which at run time will be substituted by the value of the first column for each row in the DataSet.
30
Chapter 1
04_749516 ch01.qxp 2/10/06 9:11 PM Page 30