下拉列表,DropDownList 同时显示静态和动态数据

.aspx

动态下拉:
       
       

 <asp:DropDownList ID="DropDownList1" runat="server" >
            <asp:ListItem Selected="True">----动态下拉----</asp:ListItem>
            <asp:ListItem>123456</asp:ListItem>
        </asp:DropDownList>

 

--------------------------------------------------------------

.cs

protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection myConnection = new SqlConnection("Data Source=ZL4306;Initial Catalog=kk;User ID=sa");//Data Source=这里是数据库服务器的主机名,Initial Catalog=这里是数据库名,ID=这里是登陆用户名
        SqlDataAdapter myCommand = new SqlDataAdapter("select dmsm1,dmz from kk_code where dmlb='6'", myConnection);

        DataSet ds = new DataSet();
        myCommand.Fill(ds, "dmsm1");

        DropDownList1.DataSource = ds.Tables["dmsm1"].DefaultView;
        DropDownList1.DataTextField = "dmz";
        DropDownList1.DataValueField = "dmz";
        DropDownList1.DataBind();
        DropDownList1.Items.Insert(0, "----请选择----"); //这个就是插入的静态的数据

    }

 

黑色头发  http://heisetoufa.iteye.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值