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

📄 dropdownlist.aspx.cs

📁 关于ASP.NET制作程序模块
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            banddropdownlist2();
        }
    }
    protected void btnadd_Click(object sender, EventArgs e)
    {
        if (this.TextBox1.Text == string.Empty)
        {
            Response.Write("请输入数据");
        }
        else
        {
            string aa = this.TextBox1.Text;
            DropDownList1.Items.Add(aa);
            this.labout.Text = "你刚添加了<font color=red>" + aa +"</font>";
            this.labcount.Text = "DropDownList1控件中有" + DropDownList1.Items.Count.ToString() + "项数据";
        }
    }
    protected void btndel_Click(object sender, EventArgs e)
    {
        string bb = DropDownList1.SelectedValue.ToString();
        DropDownList1.Items.Remove(bb);
        this.labout.Text = "你刚删除了<font color=red>" + bb +"</font>";
        this.labcount.Text = "DropDownList1控件中有" + DropDownList1.Items.Count.ToString() + "项数据";
    }
    protected void btndelall_Click(object sender, EventArgs e)
    {
        DropDownList1.Items.Clear();
        this.labout.Text = "全部删除成功";
        this.labcount.Text = "DropDownList1控件中有" + DropDownList1.Items.Count.ToString() + "项数据";
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.labout.Text ="你选择了:" + DropDownList1.SelectedValue.ToString();
    }
    private void banddropdownlist2()
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
        con.Open();
        string cmdtext = "select shipname from orders";
        SqlDataAdapter sda = new SqlDataAdapter(cmdtext, con);
        DataSet ds = new DataSet();
        sda.Fill(ds, "shipname");
        this.DropDownList2.DataSource = ds.Tables["shipname"].DefaultView;
        DropDownList2.DataValueField = "shipname";
        DropDownList2.DataBind();
        con.Close();
    }
}

⌨️ 快捷键说明

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