在ASP.NET中默认 没有启用Trace,首先需要在配置文件加上下面节点!【如果只需要在某个页面级使用Trace,则在page加上即可【<%@ Page Language="C#" Trace="true" TraceMode="SortByTime"】
<configuration> <system.web> <trace enabled="true" pageOutput="false" requestLimit="40" localOnly="false"/> </system.web> </configuration>
下面我写了2个页面, 数据库用的是Northwind数据库
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="datasUseGridView.aspx.cs" Inherits="testWeb.databing.datasUseGridView" EnableViewState="false" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>使1用?GridView绑ó定¨数y据Y</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False" ReadOnly="True" SortExpression="ProductID" /> <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" /> <asp:BoundField DataField="QuantityPerUnit" HeaderText="QuantityPerUnit" SortExpression="QuantityPerUnit" /> <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" /> <asp:TemplateField> <ItemTemplate> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# String.Format(@"~/databing/datadetail.aspx?id={0}",Eval("ProductID")) %>' Text="详ê细?"></asp:HyperLink> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT TOP (20) ProductID, ProductName, QuantityPerUnit, UnitPrice FROM [Alphabetical list of products]"> </asp:SqlDataSource> </div> </form> </body> </html> 首先运行该页面…
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="datasUseRepeater.aspx.cs" Inherits="testWeb.databing.datasUseRepeater" EnableViewState="false" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>使1用?Repeater绑ó定¨数y据Y</title> </head> <body> <form id="form1" runat="server"> <div> <table> <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"> <HeaderTemplate> <tr> <td> ProductID </td> <td> ProductName </td> <td> QuantityPerUnit </td> <td> UnitPrice </td> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td> <%#Eval("ProductID") %> </td> <td> <%#Eval("ProductName")%> </td> <td> <%#Eval("QuantityPerUnit")%> </td> <td> <%#Eval("UnitPrice")%> </td> <td> <a href='datadetail.aspx?id=<%#Eval("ProductID") %>'>详ê细?</a> </td> </tr> </ItemTemplate> </asp:Repeater> </table> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT TOP (20) ProductID, ProductName, QuantityPerUnit, UnitPrice FROM [Alphabetical list of products]"> </asp:SqlDataSource> </div> </form> </body> </html> 在运行该页面…
如何:使用跟踪查看器查看 ASP.NET 跟踪信息
现在在地址栏输入: http://localhost:30194/databing/trace.axd [在你运行的路径后面运行trace.axd]
点击编号1 的 查看详细信息 [使用GridView绑定数据]
点击编号2的 查看详细信息[使用Repeater绑定数据]
0.18248628031112/0.0270457468544523 = 6.747318951596225
当然比较GridView和Repeater的效率问题,需要多次测试取平均值,有时我测试他们相差很大,有时很小,如第一次运行时,需要编译,他变得很慢,后面就会快一些了! 如感兴趣的朋友可以多测试几组数据!
记录学习点滴...,坚持每天让自己的技能增加1%,默默的坚持下去吧!:-)