dropdown.aspx.cs

来自「shop sales computer, write asp.net code 」· CS 代码 · 共 78 行

CS
78
字号
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 + =
减小字号Ctrl + -
显示快捷键?