Tuesday, 29 July 2014

Using Control Parameter with Details View in ASP.NET

ASP.NET ControlParameter and DetailsView example

  1. <%@ Page Language=“C#” %>

  2. <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

  3. <script runat=“server”>

  4. </script>

  5. <html xmlns=“http://www.w3.org/1999/xhtml”>
  6. <head runat=“server”>
  7.     <title>asp.net ControlParameter and DetailsView example</title>
  8. </head>
  9. <body>
  10.     <form id=“form1″ runat=“server”>
  11.     <div>
  12.         <h2 style=“color:Teal”>ControlParameter and DetailsView</h2>
  13.         <asp:SqlDataSource
  14.              ID=“SqlDataSource1″
  15.              runat=“server”
  16.              ConnectionString=“<%$ ConnectionStrings:NorthwindConnectionString %>”
  17.              SelectCommand=“SELECT ProductID, ProductName FROM Products”
  18.              >
  19.         </asp:SqlDataSource>
  20.         <asp:SqlDataSource
  21.              ID=“SqlDataSource2″
  22.              runat=“server”
  23.              ConnectionString=“<%$ ConnectionStrings:NorthwindConnectionString %>”
  24.              SelectCommand=“SELECT ProductID, ProductName, UnitPrice FROM Products WHERE ProductID=@ProductID”
  25.              >
  26.             <SelectParameters>
  27.                 <asp:ControlParameter ControlID=“DropDownList1″ Name=“ProductID” PropertyName=“SelectedValue” />
  28.             </SelectParameters>
  29.         </asp:SqlDataSource>
  30.         <asp:Label ID=“Label1″ runat=“server” Text=“Product” AssociatedControlID=“DropDownList1″ ForeColor=“SteelBlue” Font-Bold=“true”></asp:Label>
  31.         <asp:DropDownList
  32.              ID=“DropDownList1″
  33.              runat=“server”
  34.              DataSourceID=“SqlDataSource1″
  35.              DataTextField=“ProductName”
  36.              DataValueField=“ProductID”
  37.              AutoPostBack=“true”
  38.              ForeColor=“HotPink”
  39.              >
  40.         </asp:DropDownList>
  41.         <br /><br />
  42.         <asp:Label ID=“Label2″ runat=“server” Text=“Product Details” Font-Bold=“true” ForeColor=“Gray”></asp:Label>
  43.         <asp:DetailsView
  44.              ID=“DetailsView1″
  45.              runat=“server”
  46.              DataSourceID=“SqlDataSource2″
  47.              BackColor=“Snow”
  48.              ForeColor=“IndianRed”
  49.              BorderStyle=“Double”
  50.              BorderColor=“SteelBlue”
  51.              >
  52.         </asp:DetailsView>
  53.     </div>
  54.     </form>
  55. </body>
  56. </html>



No comments:

Post a Comment