listbox.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 conNorthwind;
SqlCommand cmdSelect;
SqlDataReader dtrProducts;
conNorthwind = new SqlConnection( @"Server=localhost;Integrated Security=SSPI; Database=Northwind" );
conNorthwind.Open();
cmdSelect = new SqlCommand( "Select ProductName From Products", conNorthwind );
dtrProducts = cmdSelect.ExecuteReader();
lstProducts.DataSource = dtrProducts;
lstProducts.DataTextField = "ProductName";
lstProducts.DataBind();
dtrProducts.Close();
conNorthwind.Close();
}
}
</Script>
<html>
<head><title>ListBox.aspx</title></head>
<body>
<form Runat="Server">
<asp:ListBox
ID="lstProducts"
Runat="Server" />
<p>
<asp:Button
Text="Select A Product!"
Runat="Server" />
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?