最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

為下拉式菜單(DropDownList)添加第一個(gè)選項(xiàng)

標(biāo)簽:
JavaScript

很多方法可以为为下拉式菜单(DropDownList)添加第一个选项,下面是Insus.NET小结了几个方法,仅供参考:

Html code:

5acf07320001405b00110016.jpgView Code <body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server">            
        </asp:DropDownList>
    </div>
    </form>
</body>

 

数据源与绑定:

5acf07320001405b00110016.jpgView Code  protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Data_Binding();
        }
    }

    private void Data_Binding()
    {
        this.DropDownList1.DataSource = Site();
        this.DropDownList1.DataTextField = "key";
        this.DropDownList1.DataValueField = "value";
        this.DropDownList1.DataBind();
    }

    private Dictionary<string, string> Site()
    {
        Dictionary<string, string> site = new Dictionary<string, string>();
        site.Add("Insus.NET cnblogs", "http://insus.cnblogs.com");
        site.Add("Microsoft", "http://www.microsoft.com");
        site.Add("Google", "http://www.google.com");
        return site;
    }

 

以下所有方法,均以以上html或code作变动。

 

第一种,修改Html Code,把DropDownList属性AppendDataBoundItems的值设为true,然后直接添加一个item:<asp:ListItem Text="--选择--" Value=""></asp:ListItem> 在DropDownList内。

5acf07320001405b00110016.jpgView Code  <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true">    
        <asp:ListItem Text="--选择--" Value=""></asp:ListItem>        
        </asp:DropDownList>

 

第二种方法,Html Code无需更改,

5acf07320001405b00110016.jpgView Code  <asp:DropDownList ID="DropDownList1" runat="server" >                  
        </asp:DropDownList>

 

修改Data_Binding()方法,如下: 

5acf07320001405b00110016.jpgView Code private void Data_Binding()
    {
        this.DropDownList1.DataSource = Site();
        this.DropDownList1.DataTextField = "key";
        this.DropDownList1.DataValueField = "value";
        this.DropDownList1.DataBind();

        //添加下面代码:
        DropDownList1.Items.Insert(0, new ListItem( "--选择--",""));
         
    }

 

第三种方法:

Html改为如下,设置AppendDataBoundItems属性与及实现OnDataBound事件:

5acf07320001405b00110016.jpgView Code <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true" OnDataBound="DropDownList1_DataBound" >                  
        </asp:DropDownList>

 

cs code:

5acf07320001405b00110016.jpgView Code  protected void DropDownList1_DataBound(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        ddl.Items.Insert(0, new ListItem("--选择--", "0"));
    }

 

 

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消