zoukankan      html  css  js  c++  java
  • ListBox简单应用

    ListBox-->SelectionMode属性:列表的选择模式

    在工具箱拖放一个ListBox:

    打开源:

    <body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="txtAddListValue" runat="server"></asp:TextBox>
            <asp:Button ID="btnSubmit" runat="server" Text="新增" onclick="btnSubmit_Click" />
            <br /><br />
            <asp:ListBox ID="listValue" runat="server" SelectionMode="Multiple">
                <asp:ListItem>张三</asp:ListItem>
                <asp:ListItem>李四</asp:ListItem>
                <asp:ListItem>王五</asp:ListItem>
                <asp:ListItem>赵六</asp:ListItem>
            </asp:ListBox>
            <br /><br />
            <asp:Button ID="btnSure" runat="server" Text="选择" onclick="btnSure_Click" />
            <br />
            <asp:Label ID="labShow" runat="server"></asp:Label>
        </div>
        </form>
    </body>

    双击新增按钮:

       /// <summary>
        /// 为ListBox新加一项值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            listValue.Items.Add(txtAddListValue.Text.ToString());
        }

    双击选择按钮:

        /// <summary>
        /// 显示选择的值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSure_Click(object sender, EventArgs e)
        {
            labShow.Text = "您选择的是:<br />";
            //遍历控件
            foreach(ListItem li in listValue.Items)
            {
                //获取值
                if(li.Selected)
                {
                    labShow.Text += li.Text + "<br>";
                }
            }
        }

  • 相关阅读:
    6 docker-harbor仓库搭建
    4 dockerfile介绍及其实例应用
    1 docker 介绍和安装
    2 docker镜像
    PAT甲级1075 PAT Judge
    PAT甲级1139 First Contact【离散化】
    PAT甲级1055 The World's Richest【排序】
    PAT甲级1013-1014-1015
    洛谷P1135 奇怪的电梯【bfs】
    洛谷P1182 数列分段【二分】【贪心】
  • 原文地址:https://www.cnblogs.com/scsuns520/p/1633270.html
Copyright © 2011-2022 走看看