⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 selectpt.aspx.cs

📁 b to b 模式 电子商务系统
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using System.Data.SqlClient;
using System.Configuration ;

namespace B2Bsite
{
	/// <summary>
	/// 选择商品类型
	/// </summary>
	public class SelectPT : System.Web.UI.Page
	{
        protected System.Web.UI.WebControls.ListBox ListBox1;
        protected System.Web.UI.WebControls.ListBox ListBox2;
        protected System.Web.UI.WebControls.ListBox ListBox3;
        protected System.Web.UI.WebControls.ListBox ListBox4;
        protected System.Web.UI.WebControls.Button Button1;
        protected System.Web.UI.WebControls.ListBox ListBox5;

        public SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
        public string strName;
        public string strID;
    
		private void Page_Load(object sender, System.EventArgs e)
		{
            if( !IsPostBack )
            {
                if( Session["username"] == null )
                {
                    Response.Redirect("User_login.aspx?msg=" + Server.UrlEncode("SelectPT.aspx") );
                }
                //连续选中
                if( ListBoxDateBind(ListBox1,"0") )
					if( ListBoxDateBind(ListBox2,ListBox1.SelectedValue) )
						if( ListBoxDateBind(ListBox3,ListBox2.SelectedValue) )
							if( ListBoxDateBind(ListBox4,ListBox3.SelectedValue) )
								ListBoxDateBind(ListBox5,ListBox4.SelectedValue);
                SelectName();
            }
		}

        private bool ListBoxDateBind(ListBox ListBox,string strID)//ListBox控件的数据绑定
        {
            String sql="SELECT * FROM PType where parentId=" + strID;
            SqlCommand command=new SqlCommand(sql,conn);
			try
			{
				conn.Open();
				SqlDataReader dr=command.ExecuteReader();
				ListBox.DataSource = dr;
				ListBox.DataValueField = "category_ID";
				ListBox.DataTextField = "category_name";
				ListBox.DataBind();
				ListBox.SelectedIndex=0; //默认选中第一个选项
                dr.Close();
			}
			catch
			{
				return false;
			}
			finally
			{
				conn.Close();
			}
			return true;
        }

        private void SelectName()//获取选中的 类别名称和编号
        {
            if(ListBox1.SelectedIndex  > -1)
            {
                strName = ListBox1.SelectedItem.Text+"&gt;&gt;";
                strID = ListBox1.SelectedValue;
            }
            if(ListBox2.SelectedIndex  > -1)
            {
                strName += ListBox2.SelectedItem.Text+"&gt;&gt;";
                strID = ListBox2.SelectedValue;
            }
            if(ListBox3.SelectedIndex  > -1)
            {
                strName += ListBox3.SelectedItem.Text+"&gt;&gt;";
                strID = ListBox3.SelectedValue;
            }
            if(ListBox4.SelectedIndex  > -1)
            {
                strName += ListBox4.SelectedItem.Text+"&gt;&gt;";
                strID = ListBox4.SelectedValue;
            }
            if(ListBox5.SelectedIndex  > -1)
            {
                strName += ListBox5.SelectedItem.Text;
                strID = ListBox5.SelectedValue;
            }
        }

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
            this.ListBox1.SelectedIndexChanged += new System.EventHandler(this.ListBox1_SelectedIndexChanged);
            this.ListBox2.SelectedIndexChanged += new System.EventHandler(this.ListBox2_SelectedIndexChanged);
            this.ListBox3.SelectedIndexChanged += new System.EventHandler(this.ListBox3_SelectedIndexChanged);
            this.ListBox4.SelectedIndexChanged += new System.EventHandler(this.ListBox4_SelectedIndexChanged);
            this.ListBox5.SelectedIndexChanged += new System.EventHandler(this.ListBox5_SelectedIndexChanged);
            this.Button1.Click += new System.EventHandler(this.Button1_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
		#endregion

        private void ListBox1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
           // Response.Write(ListBox1.SelectedItem + " "+ ListBox1.SelectedValue+ "<br/>");
            if( ListBoxDateBind(ListBox2,ListBox1.SelectedValue) )
                if( ListBoxDateBind(ListBox3,ListBox2.SelectedValue) )
                    if( ListBoxDateBind(ListBox4,ListBox3.SelectedValue) )
                        ListBoxDateBind(ListBox5,ListBox4.SelectedValue);
            SelectName();
        }

        private void ListBox2_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if( ListBoxDateBind(ListBox3,ListBox2.SelectedValue) )
                if( ListBoxDateBind(ListBox4,ListBox3.SelectedValue) )
                    ListBoxDateBind(ListBox5,ListBox4.SelectedValue);
            SelectName();
        }

        private void ListBox3_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if( ListBoxDateBind(ListBox4,ListBox3.SelectedValue) )
                ListBoxDateBind(ListBox5,ListBox4.SelectedValue);
            SelectName();
        }

        private void ListBox4_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            ListBoxDateBind(ListBox5,ListBox4.SelectedValue);
            SelectName();
        }

        private void Button1_Click(object sender, System.EventArgs e)
        {
            SelectName();
            Response.Redirect("product_add.aspx?categoryid=" + strID + "&categoryname=" +
                Server.UrlEncode(strName));
        }

        private void ListBox5_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            SelectName();
        }
	}
}

⌨️ 快捷键说明

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