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

📄 dropdown.aspx.cs

📁 shop sales computer, write asp.net code c#
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class DropDown : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            show();
        }

    }

    public void show()
    {
        string connString = "Server=HIPPOPC; Database=LAPTOPSHOP; Integrated Security=SSPI";
        SqlConnection sqlConn = new SqlConnection(connString);
        sqlConn.Open();

        string commandString = "SELECT * FROM hangsx";
        SqlCommand sqlCommand = new SqlCommand();
        sqlCommand.CommandText = commandString;
        sqlCommand.Connection = sqlConn;

        SqlDataAdapter sqlDad = new SqlDataAdapter(sqlCommand);
        DataSet ds = new DataSet();
        sqlDad.Fill(ds);

        DropDownList1.DataSource = ds;
        DropDownList1.DataTextField = ds.Tables[0].Columns[1].ToString();
        DropDownList1.DataValueField = ds.Tables[0].Columns[0].ToString();
        DropDownList1.DataBind();
    }

    public void show1()
    {
        string connString = "Server=HIPPOPC; Database=LAPTOPSHOP; Integrated Security=SSPI";
        SqlConnection sqlConn = new SqlConnection(connString);
        sqlConn.Open();

        

        string commandString = "SELECT * FROM sanpham WHERE id_hangsx="+id;
        SqlCommand sqlCommand = new SqlCommand();
        sqlCommand.CommandText = commandString;
        sqlCommand.Connection = sqlConn;

        SqlDataAdapter sqlDad = new SqlDataAdapter(sqlCommand);
        DataSet ds = new DataSet();
        sqlDad.Fill(ds);

        DropDownList2.DataSource = ds;
        DropDownList2.DataTextField = ds.Tables[0].Columns[4].ToString();
        DropDownList2.DataValueField = ds.Tables[0].Columns[0].ToString();
        DropDownList2.DataBind();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        
    }
    public string id;
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        id = DropDownList1.SelectedItem.Value;
        show1();
    }
}

⌨️ 快捷键说明

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