Datasheet

<asp:BoundField DataField=”EntryText” />
</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>
In the GridView control’s markup, the DataSourceID attribute specifies the source of the data, which is
the
ObjectDataSource control. In addition, the markup specifies which columns to display by setting
AutoGenerateColumns to False. A final step is to create a list of columns:
<Columns>
<asp:BoundField DataField=”EntryDate” />
<asp:BoundField DataField=”EntryTitle” />
<asp:BoundField DataField=”EntryText” />
</Columns>
As well as enabling the display of data, the ObjectDataSource control can also update, insert, and
delete records from a database, as demonstrated shortly.
Creating, Editing, and Viewing a Diary Entry
The DayView.aspx page allows for diary editing. This page contains a simple form allowing you to enter
title and diary entry details. It also displays any existing diary entry.
All of the hard work is done by use of the
DiaryEntry class. Its Page_Load event creates a new
DiaryEntry class, passing its constructor the current user’s DiaryId and also the date the page
refers to:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
mDiaryEntry = New DiaryEntry(CInt(Session(“DiaryId”)),
CDate(dayShownLabel.Text))
changeDayCalendar.SelectedDate = CDate(dayShownLabel.Text)
changeDayCalendar.VisibleDate = changeDayCalendar.SelectedDate
If Not IsPostBack Then
entryTextTextBox.Text = mDiaryEntry.EntryText
entryTitleTextBox.Text = mDiaryEntry.EntryTitle
End If
End Sub
26
Chapter 1
04_749516 ch01.qxp 2/10/06 9:11 PM Page 26