#code private DataSet data; #end code |
#code private void BindData() { data = new DataSet(); SqlConnection cnn = new SqlConnection("Data Source=(local);Initial Catalog=pubs;Integrated Security=SSPI"); SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = new SqlCommand("SELECT stor_id, stor_name,stor_address, city, state, zip FROM stores", cnn); adapter.Fill(data, "stores"); storeList.DataSource = data; storeList.DataMember = "stores"; storeList.DataTextField = "stor_name"; storeList.DataBind(); Session.Add("Data", data); } #end code |
#code private void Page_Load(object sender, System.EventArgs e) { if(!Page.IsPostBack) { BindData(); } } #end code |
#code public class StoreSelectorCommandEventArgs { private string _stor_id; private string _stor_name; private string _stor_address; private string _city; private string _state; private string _zip; public StoreSelectorCommandEventArgs(string stor_id, string stor_name, string stor_address, string city, string state, string zip) { _stor_id = stor_id; _stor_name = stor_name; _stor_address = stor_address; _city = city; _state = state; _zip = zip; } public string stor_id{ get{ return _stor_id; } } public string stor_name{ get{ return _stor_name; } } public string stor_address{ get{ return _stor_address; } } public string city{ get{ return _city; } } public string state{ get{ return _state; } } public string zip{ get{ return _zip; } } } #end code |
#code public delegate void StoreSelectorCommandEventHandler(object sender, StoreSelectorCommandEventArgs e); #end code |
#code public event StoreSelectorCommandEventHandler StoreSelectorChanged; protected virtual void OnStoreSelectorChanged(StoreSelectorCommandEventArgs e) { if(StoreSelectorChanged != null) StoreSelectorChanged(this, e); } #end code |
#code private void storeList_SelectedIndexChanged(object sender, System.EventArgs e) { data = (DataSet)Session["Data"]; OnStoreSelectorChanged( new StoreSelectorCommandEventArgs (data.Tables["stores"].Rows[storeList.SelectedIndex].ItemArray[0].ToString (), data.Tables["stores"].Rows[storeList.SelectedIndex].ItemArray[1].ToString( ), data.Tables["stores"].Rows[storeList.SelectedIndex].ItemArray[2].ToString(), data.Tables["stores"].Rows[storeList.SelectedIndex].ItemArray[3].ToString(), data.Tables["stores"].Rows[storeList.SelectedIndex].ItemArray[4].ToString(), data.Tables["stores"].Rows[storeList.SelectedIndex].ItemArray[5].ToString( ))); } #end code |
#code private void StoreSelector1_StoreSelectorChanged(object sender, Pubs.Controls.StoreSelectorCommandEventArgs e) { Label1.Text = e.stor_id; Label2.Text = e.stor_name; Label3.Text = e.stor_address; Label4.Text = e.city; Label5.Text = e.state; Label6.Text = e.zip; } #end code |
#Code public int SelectedIndex { get{ return storeList.SelectedIndex; } set { if(!Page.IsPostBack) { BindData(); } if(value < storeList.Items.Count) { storeList.SelectedIndex = value; OnStoreSelectorChanged( new StoreSelectorCommandEventArgs (data.Tables["stores"].Rows[value].ItemArray[0].ToString(), data.Tables["stores"].Rows[value].ItemArray[1].ToString(), data.Tables["stores"].Rows[value].ItemArray[2].ToString(), data.Tables["stores"].Rows[value].ItemArray[3].ToString(), data.Tables["stores"].Rows[value].ItemArray[4].ToString(), data.Tables["stores"].Rows[value].ItemArray[5].ToString())); } } } #End Code |
#code private void Page_Load(object sender, System.EventArgs e) { // 用户初始化网页的代码 if(!Page.IsPostBack) { StoreSelector1.SelectedIndex = 0; } } #end code |