生成几种缓存页面,来进行缓存。
l 代码示例:接受参数示例,根据用户选择不同的Name显示不同的数据库内容。
最开始部分:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ OutputCache Duration="60" VaryByParam="Name" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
TimeMsg.Text = DateTime.Now.ToString("G");
}
</script>
Body内容:
<span style="font-family: Verdana">Using the Output Cache</span><b>Authors by Name:</b>
<table cellpadding="3" cellspacing="0" rules="all " style="border-left-color: black;
border-bottom-color: black; width: 700px; border-top-color: black; border-collapse: collapse;
background-color: #aaaadd; border-right-color: black">
<tr>
<td>
<a href="Default.aspx?Name=李阳">1</a></td>
<td>
<a href="Default.aspx?Name=陈胜">2</a></td>
<td>
<a href="Default.aspx?Name=夏秘密">3</a></td>
<td>
<a href="Default.aspx?Name=范玲玲">4</a></td>
</tr>
</table>
<br />
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:qimuConnectionString %>"
SelectCommand="SELECT * FROM [tab1] WHERE ([Name] = @Name)">
<SelectParameters>
<asp:QueryStringParameter Name="Name" QueryStringField="Name" DefaultValue="李阳" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<em>Last generated on:</em>
<asp:Label ID="TimeMsg" runat="server"></asp:Label >
显示效果:
Using the Output CacheAuthors by Name:
|