Datasheet
It gets its data from the ObjectDataSource control ObjectDataSource1, which in turn connects to the
Contact class’s GetContactByFirstLetter() shared method:
<asp:ObjectDataSource ID=”ObjectDataSource1” runat=”server”
SelectMethod=”GetContactsByFirstLetter”
TypeName=”Contact” DeleteMethod=”DeleteContact”>
<SelectParameters>
<asp:SessionParameter DefaultValue=”6” Name=”DiaryId”
SessionField=”DiaryId” Type=”Int32” />
<asp:Parameter Name=”FirstLetterOfSurname” Type=”Char” />
</SelectParameters>
<DeleteParameters>
<asp:ControlParameter ControlID=”GridView1” Name=”ContactId”
PropertyName=”SelectedValue”
Type=”Int64” />
</DeleteParameters>
</asp:ObjectDataSource>
The ObjectDataSource control’s DeleteMethod parameter is also hooked to the Contact class’s
DeleteContact. The GridView control has been set to show a link to delete each contact, and it’s this
method that does the actual deleting:
Public Shared Sub DeleteContact(ByVal ContactId As Long)
Dim diaryDBConn As New SqlConnection(conString)
Dim sqlString As String = “DeleteContact”
Dim sqlCmd As New SqlCommand(sqlString, diaryDBConn)
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.Parameters.AddWithValue(“@ContactId”, ContactId)
diaryDBConn.Open()
sqlCmd.ExecuteNonQuery()
diaryDBConn.Close()
sqlCmd = Nothing
diaryDBConn = Nothing
End Sub
The GridView also includes an Edit link, which when clicked navigates the user to the EditContact.aspx
page:
<asp:HyperLinkField DataNavigateUrlFields=”ContactId”
DataNavigateUrlFormatString=”~/SecureDiary/EditContact.aspx?ContactId={0}”
Text=”Edit” />
The corresponding ContactId is passed in the URL as URL data.
Adding a new user involves clicking the Add Contact link on the YourContacts.aspx page. This takes
you to a basic form for adding contact information such as name, e-mail, phone number, and so on. This
page and the EditContact.aspx page are identical in operation except for one important detail: The
EditContact.aspx page retrieves the details of the contact to be edited using the
Contact class. This hap-
pens in the
Page_Load event:
33
The Online Diary and Organizer
04_749516 ch01.qxp 2/10/06 9:11 PM Page 33