tracecategories.aspx

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

ASPX
47
字号
<%@ Page Language="C#" Trace="True" TraceMode="SortByCategory" %>
<%@ Import Namespace="System.Data.SqlClient" %>

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

void Page_Load(Object sender , EventArgs e) 
{
	SqlConnection conPubs;
	SqlCommand cmdSelect;

	conPubs = new SqlConnection( @"Server=localhost;Integrated Security=SSPI;Database=Pubs" );
	cmdSelect = new SqlCommand( "SELECT au_lname FROM Authors", conPubs );
	Trace.Warn( "Database", "Opening Connection" );
	conPubs.Open();
		dropAuthors.DataSource = cmdSelect.ExecuteReader();
		dropAuthors.DataTextField = "au_lname";
		Trace.Warn( "Database", "Binding to DropDownList" );
		dropAuthors.DataBind();
	Trace.Warn( "Database", "Closing Connection" );
	conPubs.Close();
}

void Button_Click( object s, EventArgs e ) {
  Trace.Warn( "Form", "User selected " + dropAuthors.SelectedItem.Text );
}
</Script>

<html>
<head><title>TraceCategories.aspx</title></head>
<body>
<form Runat="Server">

<h2>Choose an Author</h2>

<b>Author Last Name:<b>
<asp:DropDownList
  ID="dropAuthors"
  Runat="Server" />
<asp:Button
  Text="Select!"
  OnClick="Button_Click"
  Runat="Server" />

</form>
</body>
</html>

⌨️ 快捷键说明

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