ASP.NET ControlParameter and DetailsView example



- <%@ 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 runat=“server”>
- <title>asp.net ControlParameter and DetailsView example</title>
- </head>
- <body>
- <form id=“form1″ runat=“server”>
- <div>
- <h2 style=“color:Teal”>ControlParameter and DetailsView</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=“SteelBlue” Font-Bold=“true”></asp:Label>
- <asp:DropDownList
- ID=“DropDownList1″
- runat=“server”
- DataSourceID=“SqlDataSource1″
- DataTextField=“ProductName”
- DataValueField=“ProductID”
- AutoPostBack=“true”
- ForeColor=“HotPink”
- >
- </asp:DropDownList>
- <br /><br />
- <asp:Label ID=“Label2″ runat=“server” Text=“Product Details” Font-Bold=“true” ForeColor=“Gray”></asp:Label>
- <asp:DetailsView
- ID=“DetailsView1″
- runat=“server”
- DataSourceID=“SqlDataSource2″
- BackColor=“Snow”
- ForeColor=“IndianRed”
- BorderStyle=“Double”
- BorderColor=“SteelBlue”
- >
- </asp:DetailsView>
- </div>
- </form>
- </body>
- </html>



No comments:
Post a Comment