home *** CD-ROM | disk | FTP | other *** search
Wrap
ASP.NET Web Form | 2000-05-21 | 2.9 KB | 89 lines
<%@ Page Trace="true" TraceMode="SortByCategory" %> <%-- See also: SortByTime --%> <%@ Import NameSpace="System.Data" %> <%@ Import NameSpace="System.Data.SQL" %> <html> <script language="C#" runat="server"> public void Page_Load(Object sender, EventArgs E) { Trace.Warn("Custom Trace","Beginning User Code..."); if (!IsPostBack) { Trace.Write("CustomTrace","PostBack=true"); SQLConnection myConnection = new SQLConnection("server=localhost;uid=sa;pwd=;database=grocertogo"); SQLDataSetCommand myCommand = new SQLDataSetCommand("select distinct CategoryName from Categories", myConnection); DataSet ds = new DataSet(); myCommand.FillDataSet(ds, "Categories"); if (Trace.IsEnabled) { for (int i=0; i<ds.Tables["Categories"].Rows.Count; i++) { Trace.Write("ProductCategory",ds.Tables["Categories"].Rows[i][0].ToString()); } } Categories.DataSource = ds.Tables["Categories"].DefaultView; Categories.DataBind(); } } public void Submit_Click(Object sender, EventArgs E) { Trace.Write("CustomTrace","Entering Submit Handler..."); SQLConnection myConnection = new SQLConnection("server=localhost;uid=sa;pwd=;database=grocertogo"); 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); DataSet ds = new DataSet(); myCommand.FillDataSet(ds, "Products"); Products.DataSource = ds.Tables["Products"].DefaultView; Products.DataBind(); Trace.Write("CustomTrace","Leaving Submit Handler..."); } </script> <body style="font: 10pt verdana" bgcolor="ffffcc"> <form runat="server"> <h3>Writing Custom Trace Ouput to a Page</h3> Select a Category: <ASP:DropDownList id="Categories" DataValueField="CategoryName" runat="server"/> <input type="Submit" OnServerClick="Submit_Click" Value="Get Products" runat="server"/><p> <ASP:DataList id="Products" ShowHeader=false ShowFooter=false RepeatDirection="horizontal" BorderWidth=0 runat="server"> <template name="itemtemplate"> <table> <tr> <td width="150" style="text-align:center; font-size:8pt; vertical-align:top; height:200"> <ASP:ImageButton borderwidth=6 bordercolor="#ffffcc" command="Select" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImagePath") %>' runat="server"/> <p> <%# DataBinder.Eval(Container.DataItem, "ProductName") %> <br> <%# DataBinder.Eval(Container.DataItem, "UnitPrice", "{0:C}").ToString() %> </td> </tr> </table> </template> </ASP:DataList> </form> </body> </html>