ASP.NET DetailsView and ControlParameter example

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>








Related asp.net example