<html>
<title>Using Image Buttons in a CommandField</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
void setDefaultInsertDate ( Object src, EventArgs e ) {
if ( guestDetails.CurrentMode == DetailsViewMode.Insert ) {
Calendar insertCalendar = ( Calendar ) guestDetails.FindControl ( "insertluckydatecalendar" );
insertCalendar.SelectedDate = DateTime.Today;
}
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>Using Image Buttons in a CommandField</h2></div>
<hr size=1 width=92%>
<form runat="server">
<div align="center">
<asp:detailsview id="guestDetails" runat="server"
width=75% cellpadding=5
datasourceid="guests"
datakeynames="GuestID"
allowpaging
autogeneraterows=false
onDataBound="setDefaultInsertDate">
<rowstyle
backcolor="ghostwhite"
verticalalign="top" />
<commandrowstyle font-bold
horizontalalign="center" />
<fieldheaderstyle width=30%
backcolor="lightsteelblue"
horizontalalign="right" />
<fields>
<asp:boundfield datafield="guestid"
headertext="Guest ID"
insertvisible="false"
readonly="true" />
<asp:boundfield datafield="nickname"
headertext="Nickname" />
<asp:templatefield headertext="Gender">
<itemtemplate>
<asp:label id="genderlabel" runat="server"
text='<%# Eval ( "gender" ) %>' />
</itemtemplate>
<insertitemtemplate>
<asp:radiobuttonlist id="insertgender" runat="server"
repeatdirection="horizontal"
selectedvalue='<%# Bind ( "gender" ) %>'>
<asp:listitem value="M" text="Male" />
<asp:listitem value="F" text="Female" />
<asp:listitem value="" text="No Comment" />
</asp:radiobuttonlist>
</insertitemtemplate>
<edititemtemplate>
<asp:radiobuttonlist id="editgender" runat="server"
repeatdirection="horizontal"
selectedvalue='<%# Bind ( "gender" ) %>'>
<asp:listitem value="M" text="Male" />
<asp:listitem value="F" text="Female" />
<asp:listitem value="" text="No Comment" />
</asp:radiobuttonlist>
</edititemtemplate>
</asp:templatefield>
<asp:templatefield headertext="State">
<itemtemplate>
<asp:label id="statelabel" runat="server"
text='<%# Eval ( "state" ) %>' />
</itemtemplate>
<insertitemtemplate>
<asp:dropdownlist id="insertstate" runat="server"
datasourceid="states"
datatextfield="state"
datavaluefield="stateid"
selectedvalue='<%# Bind ( "state" ) %>' />
</insertitemtemplate>
<edititemtemplate>
<asp:dropdownlist id="editstate" runat="server"
datasourceid="states"
datatextfield="state"
datavaluefield="stateid"
selectedvalue='<%# Bind ( "state" ) %>' />
</edititemtemplate>
</asp:templatefield>
<asp:templatefield headertext="Lucky Date">
<itemtemplate>
<asp:label id="luckydatelabel" runat="server"
text='<%# Eval ( "luckydate", "{0:d}" ) %>' />
</itemtemplate>
<insertitemtemplate>
<asp:calendar id="insertluckydatecalendar" runat="server"
backcolor="khaki"
titlestyle-backcolor="yellowgreen"
selecteddaystyle-backcolor="sienna"
selecteddate='<%# Bind ( "luckydate" ) %>' />
</insertitemtemplate>
<edititemtemplate>
<asp:calendar id="editluckydatecalendar" runat="server"
backcolor="khaki"
titlestyle-backcolor="yellowgreen"
selecteddaystyle-backcolor="sienna"
visibledate='<%# Eval ( "luckydate" ) %>'
selecteddate='<%# Bind ( "luckydate" ) %>' />
</edititemtemplate>
</asp:templatefield>
<asp:checkboxfield datafield="married"
headertext="Married?" />
<asp:commandfield
showinsertbutton
showeditbutton
showdeletebutton
buttontype="image"
newimageurl="~/shared/images/button_add.gif"
insertimageurl="~/shared/images/button_insert.gif"
editimageurl="~/shared/images/button_edit.gif"
updateimageurl="~/shared/images/button_update.gif"
deleteimageurl="~/shared/images/button_delete.gif"
cancelimageurl="~/shared/images/button_cancel.gif" />
</fields>
<emptydatatemplate>
<center>
<p id="msg">There seems to be a problem.<br>
Some whacko must have deleted all the existing records. <img src="/shared/biggrin.gif" width="15" height="15" border="0" alt=""></p>
<p><a href="/admin/add_guests.aspx">Add Sample Data</a></p>
</center>
</emptydatatemplate>
</asp:detailsview>
<asp:sqldatasource id="guests" runat="server"
selectcommand="SELECT * FROM aspx_guests"
insertcommand="INSERT INTO aspx_guests
( Nickname, Gender, LuckyDate, State, Married ) VALUES
( @Nickname, @Gender, @LuckyDate, @State, @Married )"
updatecommand="UPDATE aspx_guests SET
Nickname=@Nickname, Gender=@Gender,
LuckyDate=@LuckyDate, State=@State, Married=@Married
WHERE GuestId=@GuestId"
deletecommand="DELETE FROM aspx_guests WHERE GuestId=@GuestId"
connectionstring="<%$ ConnectionStrings:aspnet %>" />
<asp:accessdatasource id="states" runat="server"
datafile="~/app_data/usa.mdb"
datasourcemode="datareader"
selectcommand="SELECT State, StateId FROM States" />
</div>
</form>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>