zoukankan      html  css  js  c++  java
  • DropDownList ,select 添加默认 选项的几种方法

     
    1.       <asp:DropDownList ID="DropDownList1" runat="server">
                </asp:DropDownList>
                <asp:DropDownList ID="DropDownList2" runat="server" AppendDataBoundItems="true">
                    <asp:ListItem Text="请选择" Value=""></asp:ListItem>
                </asp:DropDownList>
    2.    /**//*
        protected void DropDownList1_DataBound(object sender, EventArgs e)
        {
            DropDownList1.Items.Insert(0, new ListItem("--请选择--", ""));
        }*/
    3.

    protected void Page_Load(object sender, EventArgs e)
        ...{
            if (!IsPostBack)
            ...{
                //DropDownList的属性AppendDataBoundItems
                //功能:指示是否在数据绑定之前清除列表           
                DropDownList1.AppendDataBoundItems = true;

                DropDownList1.Items.Add(new ListItem("-- 请选择一个选择项 --", ""));

              DropDownList1.DataSource = CreateDataSource();         }
        }
    4.

    protected void Page_Load(object sender, EventArgs e)
        ...{
            if (!IsPostBack)
            ...{
                  DropDownList1.DataSource = CreateDataSource();
                 DropDownList1.Items.Insert(0,new ListItem("-- 请选择一个选择项 --", ""));
            }
        }

  • 相关阅读:
    JAVA基础知识之多线程——线程通信
    为Apache配置虚拟机Virtual Host
    SignalR的坑爹细节
    ashx入侵
    aspnet5安装ef7备忘
    aspnet5备忘
    NHibernate初步使用
    MVC中发生System.Data.Entity.Validation.DbEntityValidationException验证异常的解决方法
    关于NLog的target和Layout
    泛型约束的大概模样
  • 原文地址:https://www.cnblogs.com/tongdengquan/p/6090570.html
Copyright © 2011-2022 走看看