productpagebyparamcache.aspx

来自「asp.net技术内幕的书配源码」· ASPX 代码 · 共 42 行

ASPX
42
字号
<%@ Page Language="C#" %>
<%@ OutputCache Duration="300" VaryByParam="PID" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script language="C#" runat=server>

void Page_Load(Object sender , EventArgs e) 
{
	string  strProductID;
	SqlConnection conNorthwind;
	string  strSelect;
	SqlCommand cmdSelect;
	SqlDataReader dtrProducts;

	strProductID = Request.Params[ "PID" ];
	if ( strProductID == null )
	{
		strProductID = "1";
	}
	conNorthwind = new SqlConnection( @"Server=localhost;Integrated Security=SSPI;Database=Northwind" );
	strSelect = "Select * From Products Where ProductID=" + strProductID;
	cmdSelect = new SqlCommand( strSelect, conNorthwind );
	conNorthwind.Open();
	dgrdProducts.DataSource = cmdSelect.ExecuteReader();
	dgrdProducts.DataBind();
	conNorthwind.Close();
}
</Script>
<html>
<head><title>ProductPageByParamCache.aspx</title></head>
<body>

<asp:DataGrid
  ID="dgrdProducts"
  CellPadding="10"
  Runat="Server" />
<hr>
<small>Last Updated: <%=DateTime.Now%></small>

</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?