<html>
<head>
<title>GridView SelectedValue Example</title>
<link rel="stylesheet" href="/shared/netdemos.css">
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>GridView <span class="hilite">SelectedValue</span> Example</h2></div>
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<table width="90%" cellpadding=10>
<tr valign="top">
<td width="40%" align="center">
Select Subject: <asp:dropdownlist id="lstTypes" runat="server"
datasourceid="bookTypes"
datatextfield="Type"
autopostback />
<p>
<asp:gridview id="gvTitles" width=100% runat="server"
datasourceid="bookTitles"
datakeynames="title_id"
autogeneratecolumns=false
gridlines="both" cellpadding=5 font-size="10pt">
<headerstyle backcolor="lightsteelblue" font-bold />
<selectedrowstyle backcolor="beige" font-italic />
<columns>
<asp:buttonfield headertext="Title"
datatextfield="Title"
commandname="Select" />
<asp:boundfield headertext="TitleID"
datafield="title_id" />
<asp:boundfield headertext="Price"
datafield="price"
dataformatstring="{0:c}" />
</columns>
</asp:gridview>
</td>
<td width="55%">
<asp:formview id="fvDetails" runat="server"
datasourceid="bookDetails">
<itemtemplate>
<div class="header"><h3 style="color:maroon">
<%# Eval ( "title" ) %>
</h2></div>
<table cellpadding=5>
<tr>
<td valign="top">
<img align="top" runat="server"
src='<%# Eval ( "title_id", "~/shared/images/title-{0}.gif" ) %>'>
</td>
<td valign="top">
<p><%# Eval ( "notes" ) %></p>
<p>
<b>Category:</b> <%# Eval ( "type" ) %><br>
<b>Publisher ID:</b> <%# Eval ( "pub_id" ) %><br>
<b>Price:</b> <%# Eval ( "price", "{0:c}" ) %>
</p>
</td></tr>
</table><br>
</itemtemplate>
</asp:formview>
</td></tr>
</table>
<asp:sqldatasource id="bookTypes" runat="server"
datasourcemode="datareader"
selectcommand="SELECT DISTINCT Type FROM Titles"
connectionstring="<%$ ConnectionStrings:aspnet %>" />
<asp:sqldatasource id="bookTitles" runat="server"
selectcommand="SELECT * FROM Titles"
filterexpression="Type='{0}'"
connectionstring="<%$ ConnectionStrings:aspnet %>">
<filterparameters>
<asp:controlparameter controlid="lstTypes"
propertyname="SelectedValue" />
</filterparameters>
</asp:sqldatasource>
<asp:sqldatasource id="bookDetails" runat="server"
datasourcemode="datareader"
selectcommand="SELECT * FROM Titles WHERE title_id = @title_id"
connectionstring="<%$ ConnectionStrings:aspnet %>">
<selectparameters>
<asp:controlparameter controlid="gvTitles"
name="title_id" type="string"
propertyname="SelectedValue" />
</selectparameters>
</asp:sqldatasource>
</form>
</div>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>