dropdownlist.aspx

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

ASPX
45
字号
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat=server>

void Page_Load(Object sender , EventArgs e) 
{
	if (! IsPostBack ) {
		SqlConnection conPubs;
		SqlCommand cmdSelect;
		SqlDataReader dtrAuthors;

		conPubs = new SqlConnection( @"Server=localhost;Integrated Security=SSPI; Database=Pubs" );
		conPubs.Open();
		cmdSelect = new SqlCommand( "Select au_lname From Authors", conPubs );
		dtrAuthors = cmdSelect.ExecuteReader();

		dropAuthors.DataSource = dtrAuthors;
		dropAuthors.DataTextField = "au_lname";
		dropAuthors.DataBind();

		dtrAuthors.Close();
		conPubs.Close();
	}
}

</Script>

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

<asp:DropDownList
  ID="dropAuthors"
  Runat="Server" />

<asp:Button
  Text="Pick Author!"
  Runat="Server" />

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

⌨️ 快捷键说明

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