• 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("-- 请选择一个选择项 --", ""));
            }
        }

  • 相关阅读:
    python3.6虚拟环境
    安装VMwareTools
    Vsftpd配置(Centos7)
    Sftp配置
    权限问题
    Zabbix5.0微信报警
    K8s Scheduler 在调度 pod 过程中遗漏部分节点的问题排查
    Getting Started and Beyond|云原生应用负载均衡选型指南
    混部之殇-论云原生资源隔离技术之CPU隔离(一)
    云原生技术开放日PPT大放送 | 五星级的云原生开发体验
  • 原文地址:https://www.cnblogs.com/tongdengquan/p/6090570.html
Copyright © 2020-2023  润新知