DetailsView and ControlParameter
DetailsViewControlParameter.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net DetailsView and ControlParameter example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Teal">ControlParameter Example</h2>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT ProductID, ProductName FROM Products"
>
</asp:SqlDataSource>
<asp:SqlDataSource
ID="SqlDataSource2"
runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT ProductID, ProductName, UnitPrice FROM Products WHERE ProductID=@ProductID"
>
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="ProductID" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Label ID="Label1" runat="server" Text="Product" AssociatedControlID="DropDownList1" ForeColor="Green"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="ProductName" DataValueField="ProductID" AutoPostBack="true" >
</asp:DropDownList>
<br /><br />
<asp:DetailsView
ID="DetailsView1"
runat="server"
DataSourceID="SqlDataSource2"
ForeColor="SlateGray"
BackColor="Snow"
BorderColor="HotPink"
AutoGenerateRows="false"
>
<Fields>
<asp:BoundField HeaderText="ID" DataField="ProductID" />
<asp:BoundField HeaderText="Name" DataField="ProductName" />
<asp:BoundField HeaderText="Unit Price" DataField="UnitPrice" />
</Fields>
<HeaderStyle BackColor="HotPink" />
<HeaderTemplate>
<asp:Label ID="Label1" runat="server" Text="Product Details" ForeColor="AntiqueWhite" Font-Size="Large"></asp:Label>
</HeaderTemplate>
</asp:DetailsView>
</div>
</form>
</body>
</html>
- asp.net GridView example: a sample simple Master-Details page
- asp.net SqlDataSource example: using FilterParameters, FilterExpression
- asp.net SqlDataSource example: SelectCommandType StoredProcedure
- asp.net QueryStringParameter example: how to use asp:QueryStringParameter
- asp.net SqlDataSource example: DataSourceMode DataSet
- asp.net SqlDataSource example: DataSourceMode DataReader
- asp.net GridView HeaderStyle, AlternatingRowStyle example
- asp.net DetailsView HeaderTemplate, HeaderStyle, AlternatingRowStyle example
- asp.net DetailsView Fields, BoundField, PagerSettings, PagerStyle example
- asp.net GridView PagerSettings and PagerStyle example
- asp.net GridView Paging example: how to Paging GridView Data
- asp.net GridView Sorting example: how to sort GridView Data
- asp.net BoundField example: how to use asp:BoundFiled