zoukankan      html  css  js  c++  java
  • dropdownlist的动态绑定数据然后怎么添加默认项“请选择”或空值

    有两种方法:一种是用dual表查空值,然后绑定。另一种是先动态绑定数据后,然后插入一列默认项。

    eg1:
    string selectQuery = "select  null extattrid,null extattrname from dual union all select  extattrid,extattrname from VExtAttrDetail where extattrsn in (22)";
         DataSet ds=dboperReq.GetDSet(selectQuery);
        ddlTrantype.DataTextField = "extattrname";
        ddlTrantype.DataValueField="extattrid";
        ddlTrantype.DataSource=ds.Tables[0].DefaultView;
        ddlTrantype.DataBind();

    eg2:
     string selectQuery = "select  extattrid,extattrname from VExtAttrDetail where extattrsn in (22)";
        DataSet ds=dboperReq.GetDSet(selectQuery);
        ddlTrantype.DataTextField = "extattrname";
        ddlTrantype.DataValueField="extattrid";
        ddlTrantype.DataSource=ds.Tables[0].DefaultView;
        ddlTrantype.DataBind();
        ddlTrantype.Items.Insert(0,new ListItem(" "," ")); //或者ListItem it = new ListItem("请选择", "0");
    //mydroplist.Items.Insert(0,it);     或者 ListItem lt = new ListItem();
    //lt.Text = "请选择";
    //lt.Value = "00";
    //lt.Selected = true;
    //ddp.Items.Add(lt);

  • 相关阅读:
    C/S模式客户端连接服务器连接不上的问题
    C#获取网络状态
    SQL2008R转SQL2005
    Centos7 调整磁盘空间
    crontab 定时任务
    nginx 简单教程
    vagrant 使用
    加快 hive 查询的 5 种方法
    编译 ambari 2.7.3
    kylin 连接 hortonworks 中的 hive 遇到的问题
  • 原文地址:https://www.cnblogs.com/jameshappy/p/1382492.html
Copyright © 2011-2022 走看看