home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / aspplus / samples / trace / trace2.aspx < prev    next >
Encoding:
ASP.NET Web Form  |  2000-05-21  |  2.9 KB  |  89 lines

  1. <%@ Page Trace="true" TraceMode="SortByCategory" %>
  2. <%-- See also: SortByTime --%>
  3.  
  4. <%@ Import NameSpace="System.Data" %>
  5. <%@ Import NameSpace="System.Data.SQL" %>
  6.  
  7.  
  8. <html>
  9.  
  10. <script language="C#" runat="server">
  11.  
  12.   public void Page_Load(Object sender, EventArgs E)
  13.   {
  14.     Trace.Warn("Custom Trace","Beginning User Code...");
  15.  
  16.     if (!IsPostBack)
  17.     {
  18.       Trace.Write("CustomTrace","PostBack=true");
  19.  
  20.       SQLConnection myConnection = new SQLConnection("server=localhost;uid=sa;pwd=;database=grocertogo");
  21.       SQLDataSetCommand myCommand = new SQLDataSetCommand("select distinct CategoryName from Categories", myConnection);
  22.  
  23.       DataSet ds = new DataSet();
  24.       myCommand.FillDataSet(ds, "Categories");
  25.  
  26.       if (Trace.IsEnabled)
  27.       {
  28.         for (int i=0; i<ds.Tables["Categories"].Rows.Count; i++)
  29.         {
  30.           Trace.Write("ProductCategory",ds.Tables["Categories"].Rows[i][0].ToString());
  31.         }
  32.       }
  33.  
  34.       Categories.DataSource = ds.Tables["Categories"].DefaultView;
  35.       Categories.DataBind();
  36.     }
  37.   }
  38.  
  39.   public void Submit_Click(Object sender, EventArgs E)
  40.   {
  41.     Trace.Write("CustomTrace","Entering Submit Handler...");
  42.  
  43.     SQLConnection myConnection = new SQLConnection("server=localhost;uid=sa;pwd=;database=grocertogo");
  44.     SQLDataSetCommand myCommand = new SQLDataSetCommand("select ProductName, ImagePath, UnitPrice, c.CategoryId  from Products p, Categories c where c.CategoryName='" + Categories.SelectedItem.Value + "' and p.CategoryId = c.CategoryId", myConnection);
  45.  
  46.     DataSet ds = new DataSet();
  47.     myCommand.FillDataSet(ds, "Products");
  48.  
  49.     Products.DataSource = ds.Tables["Products"].DefaultView;
  50.     Products.DataBind();
  51.  
  52.     Trace.Write("CustomTrace","Leaving Submit Handler...");
  53.   }
  54.  
  55. </script>
  56.  
  57. <body style="font: 10pt verdana" bgcolor="ffffcc">
  58.  
  59.   <form runat="server">
  60.  
  61.   <h3>Writing Custom Trace Ouput to a Page</h3>
  62.  
  63.   Select a Category: 
  64.  
  65.   <ASP:DropDownList id="Categories" DataValueField="CategoryName" runat="server"/>
  66.  
  67.   <input type="Submit" OnServerClick="Submit_Click" Value="Get Products" runat="server"/><p>
  68.  
  69.   <ASP:DataList id="Products" ShowHeader=false ShowFooter=false RepeatDirection="horizontal" BorderWidth=0 runat="server">
  70.  
  71.     <template name="itemtemplate">
  72.       <table>
  73.         <tr>
  74.           <td width="150" style="text-align:center; font-size:8pt; vertical-align:top; height:200">
  75.             <ASP:ImageButton borderwidth=6 bordercolor="#ffffcc" command="Select" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImagePath") %>' runat="server"/>
  76.             <p>
  77.             <%# DataBinder.Eval(Container.DataItem, "ProductName") %> <br>
  78.             <%# DataBinder.Eval(Container.DataItem, "UnitPrice", "{0:C}").ToString() %>
  79.           </td>
  80.         </tr>
  81.       </table>
  82.     </template>
  83.                                              
  84.   </ASP:DataList>
  85.  
  86.   </form> 
  87.  
  88. </body>
  89. </html>