Datasheet
In addition, the code specifies a Delete button on each row in the grid:
<asp:CommandField ShowDeleteButton=”True” />
When you click the Delete button, the GridView control asks the ObjectDataSource control to call the
specified delete method of the data providing class. In this case it’s the
DeleteEvent() method of the
DiaryEvent class. The DataKeyNames attribute in the GridView control’s markup specifies the primary
key field that needs to be used to delete the row.
Returning to editing the event: When you click the Edit link you are taken to the EditEvent.aspx page.
The clicked Edit link’s
EventId is passed as a URL parameter. The EditEvent.aspx page is virtually iden-
tical to the AddEvent.aspx page discussed previously. The main difference is when the page initializes.
The
Page_Init event handler is shown in the following code, and it’s here that the event details are
entered into the form:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Init
Dim EventBeingEdited As New
DiaryEvent(CLng(Request.QueryString(“EventId”)))
eventNameTextBox.Text = EventBeingEdited.EventName
eventDescriptionTextBox.Text = EventBeingEdited.EventDescription
dayShownLabel.Text = EventBeingEdited.EventDate.Day & “ “ &
MonthName(EventBeingEdited.EventDate.Month) & “ “ & EventBeingEdited.EventDate.Year
Dim NewListItem As ListItem, HourCount, MinuteCount
For HourCount = 0 To 23
If HourCount < 10 Then
NewListItem = New ListItem(“0” & HourCount, HourCount.ToString)
Else
NewListItem = New ListItem(HourCount.ToString, HourCount.ToString)
End If
If EventBeingEdited.EventDate.Hour = HourCount Then
NewListItem.Selected = True
End If
StartHourDropDownList.Items.Add(NewListItem)
Next
For MinuteCount = 0 To 59
If MinuteCount < 10 Then
NewListItem = New ListItem(“0” & MinuteCount.ToString,
MinuteCount.ToString)
Else
NewListItem = New ListItem(MinuteCount.ToString,
MinuteCount.ToString)
End If
If EventBeingEdited.EventDate.Minute = MinuteCount Then
NewListItem.Selected = True
End If
StartMinuteDropDownList.Items.Add(NewListItem)
Next
Dim itemToSelect As ListItem
31
The Online Diary and Organizer
04_749516 ch01.qxp 2/10/06 9:11 PM Page 31