<html>
<head>
<title>FormView EditItemTemplate Example</title>
<link rel="stylesheet" href="/shared/netdemos.css">
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>FormView <span class="hilite">EditItemTemplate</span> Example</h2></div>
<hr size=1 width=92%>
<form runat="server">
<div align="center">
<asp:formview id="msgView" runat="server"
datasourceid="messages"
datakeynames="MessageID"
width=80% cellpadding=5
gridlines="horizontal"
allowpaging>
<rowstyle
backcolor="yellowgreen"
borderstyle="outset"
borderwidth="1px"
horizontalalign="center" />
<editrowstyle
backcolor="khaki"
borderstyle="inset"
borderwidth="1px"
horizontalalign="center" />
<itemtemplate>
<table width=100% cellpadding=5 border=0>
<col width=25% valign="top" align="right">
<tr>
<td>Date:</td>
<td><b><%# Eval ( "MessageDate" ) %></b></td></tr>
<tr>
<td>Name:</td>
<td><b><%# Eval ( "MessageFrom" ) %></b></td></tr>
<tr>
<td>Email:</td>
<td><b><%# Eval ( "Email" ) %></b></td></tr>
<tr>
<td>Subject:</td>
<td><b><%# Eval ( "MessageSubject" ) %></b></td></tr>
<tr>
<td>Message:</td>
<td><b><%# Eval ( "MessageBody" ) %></b></td></tr>
<tr>
<td colspan="2">
<asp:button id="editbutton"
text=" Edit "
commandname="Edit"
runat="server" />
</td></tr>
</table>
</itemtemplate>
<edititemtemplate>
<h5>To save changes to the database, press Accept.</h5>
<table width=100% cellpadding=5 border=0>
<col width=25% valign="top" align="right">
<tr>
<td>Name:</td>
<td><asp:textbox maxlength=254 id="msgFrom" runat="server"
text=<%# Bind ( "MessageFrom" ) %> />
<asp:requiredfieldvalidator
controltovalidate="msgFrom"
errormessage="Sender's name cannot be blank. "
runat="server">*</asp:requiredfieldvalidator></td></tr>
<tr>
<td>Email:</td>
<td><asp:textbox maxlength=254 id="msgEmail" runat="server"
text=<%# Bind ( "Email" ) %> />
<asp:regularexpressionvalidator
controltovalidate="msgEmail"
validationexpression="^[\w-]+@[\w-]+\.(com|net|org|edu|mil)$"
errormessage="Please enter a valid e-mail address. "
runat="server">*</asp:regularexpressionvalidator></td></tr>
<tr>
<td>Subject:</td>
<td><asp:textbox maxlength=254 id="msgSubject" runat="server"
text=<%# Bind ( "MessageSubject" ) %> /></td></tr>
<tr>
<td>Message:</td>
<td><asp:textbox id="msgBody" textmode="multiline" rows=5 columns=50 runat="server"
text=<%# Bind ( "MessageBody" ) %> /></td></tr>
<tr>
<td colspan="2">
<asp:button id="updatebutton"
text=" Accept "
commandname="Update"
runat="server" />
<asp:button id="cancelbutton"
text=" Cancel "
commandname="Cancel"
runat="server" />
</td></tr>
</table>
<asp:validationsummary runat="server"
displaymode="SingleParagraph"
showmessagebox=true />
</edititemtemplate>
<emptydatatemplate>
<center>
<p id="msg">There seems to be a problem.<br>
Some whacko must have deleted all the existing records. </p>
<p><a href="/admin/add_messages.aspx">Add Records</a></p>
</center>
</emptydatatemplate>
</asp:formview>
<asp:sqldatasource id="messages" runat="server"
selectcommand="SELECT * FROM aspx_messages"
updatecommand="UPDATE aspx_messages SET
MessageFrom=@MessageFrom, Email=@Email, MessageSubject=@MessageSubject, MessageBody=@MessageBody
WHERE MessageID=@MessageID"
connectionstring="<%$ ConnectionStrings:aspnet %>" />
</div>
</form>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>