shipmethod.cs

来自「东软内部材料(四)asp等相关的教学案例 」· CS 代码 · 共 46 行

CS
46
字号
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

public class ShipMethodClass : UserControl
{
	// public variables to match the server controls
	public DropDownList   ShipMethod;
	public Label      YouSelected;
	public Button      PlaceOrder;

	public void Page_Load(Object Source, EventArgs E)
	{
	   if (!Page.IsPostBack)
	   {
		  SqlConnection   myConnection;
		  SqlCommand   myCommand;
		  SqlDataReader   myReader;
		  String      SQL;
		  String      ConnStr;

		  SQL = "select * from Shippers";
		  ConnStr = ConfigurationSettings.AppSettings["DsnNorthwind"];

		  myConnection = new SqlConnection(ConnStr);
		  myConnection.Open();

		  myCommand = new SqlCommand(SQL, myConnection);

		  myReader = myCommand.ExecuteReader();
		  ShipMethod.DataTextField = "CompanyName";
		  ShipMethod.DataSource = myReader;
		  ShipMethod.DataBind();
		}
   }

   public void ShipMethod_Change(Object Source, EventArgs E)
   {
	   YouSelected.Text = "Your order will be delivered via " +
						   ShipMethod.SelectedItem.Text;
   }
}

⌨️ 快捷键说明

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