前台:

  <div>
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" Height="66px" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged1" Width="80px">
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:ListBox>
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>

后台

第一种foreach循环

protected void ListBox1_SelectedIndexChanged1(object sender, EventArgs e)
{ string strHobby = "";
foreach (ListItem item in ListBox1.Items)
{ if (item.Selected)
{
strHobby += item.Value + ""; }
} Label1.Text = strHobby;
}

for循环

    protected void ListBox1_SelectedIndexChanged1(object sender, EventArgs e)
{
string strHobby = "";
for (int i = ; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected)
{
strHobby += ListBox1.Items[i].Value ;
}
}
Label1.Text = strHobby;
}

ListBox1控件的更多相关文章

  1. 常用的WebForm 控件

    首先回忆一下Html页中的12个表单元素 .文本类 文本框 <input type="text" id="" name="" valu ...

  2. 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch

    [源码下载] 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch 作者:webabcd 介绍背水一 ...

  3. WebForm(二)——控件和数据库连接方式

    一.简单控件 1.Label(作用:显示文字) Web中: <asp:Label ID="Label1" runat="server" Text=&quo ...

  4. winform窗体(二)——控件

    一.窗体的事件 每一个窗体都有一个事件,这个窗体加载完成之后执行哪一段代码 位置:1)右键属性→事件→load 双击进入 2)双击窗体任意一个位置进入 删除事件:先将事件页面里面的挂好的事件删除,再删 ...

  5. winform窗体控件(全)

    回顾跟补充下除了昨天那常用6个其他的winform窗体控件作用 1:Button:按钮 (1)AutoSize:如果是True的情况下,内容将会撑开:False的话会另起一行 (2)Enabled: ...

  6. WindowsForm公共控件--2016年12月5日

    Button text:修改按钮显示的文字 CheckBox Checked:是否选中 CheckedListBox checkedListBox.Items.Add(显示的值,初始选中状态); ch ...

  7. C#常用控件介绍

                                                  目录 1.窗体(Form) 2.Label (标签)控件 3.TextBox(文本框)控件 4.RichTe ...

  8. WebForm 常用控件

    一.简单控件 1.Label(作用:显示文字) Web中: <asp:Label ID="Label1" runat="server" Text=&quo ...

  9. ASPX.Net控件

    简单控件 Label :显示文字,编译后的元素的为span 主要设置属性边框包括边框颜色,边框样式,边框粗细 Liteal :显示文字,编译后不会产生任何元素,一般用来从后台输出JS代码 Textbo ...

随机推荐

  1. nginx 的中文配置详细解释

    文章转自:http://www.ha97.com/5194.html 更详细的模块参数请参考:http://wiki.nginx.org/Main #定义Nginx运行的用户和用户组 user www ...

  2. poj1509 最小表示法

    #include<stdio.h> #include<string.h> #define maxn 10010 char s[maxn]; int getmin() { int ...

  3. 【HDU 5363】Key Set

    题 Description soda has a set $S$ with $n$ integers $\{1, 2, \dots, n\}$. A set is called key set if ...

  4. Message

    * Defines a message containing a description and arbitrary data object that can be* sent to a {@link ...

  5. Linux下安装Nginx详细图解教程

    什么是Nginx? Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器,在高连接并发的情况下N ...

  6. Java Base64、AES、SHA1、MD5加密算法

    package com.example.decript; import java.io.UnsupportedEncodingException; import java.security.Inval ...

  7. nginx负载均衡的配置方法

    upstream www.***.com { server ; server ; server ; } server { listen ; server_name www.***.com; #char ...

  8. 平衡二叉树,AVL树之图解篇

    学习过了二叉查找树,想必大家有遇到一个问题.例如,将一个数组{1,2,3,4}依次插入树的时候,形成了图1的情况.有建立树与没建立树对于数据的增删查改已经没有了任何帮助,反而增添了维护的成本.而只有建 ...

  9. Java I/O操作

    按字节读取读取文件,并且将文件里面的内容写到另外一个文件里面去 public class CopyBytes { public static void main(String[] args) thro ...

  10. WPF 显示gif

    using System; using System.IO; using System.Collections.Generic; using System.Windows; using System. ...