前台:

  1. <div>
  2. <asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" Height="66px" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged1" Width="80px">
  3. <asp:ListItem></asp:ListItem>
  4. <asp:ListItem></asp:ListItem>
  5. <asp:ListItem></asp:ListItem>
  6. <asp:ListItem></asp:ListItem>
  7. </asp:ListBox>
  8. <asp:Label ID="Label1" runat="server"></asp:Label>
  9. </div>

后台

第一种foreach循环

  1. protected void ListBox1_SelectedIndexChanged1(object sender, EventArgs e)
  2. {
  3.  
  4. string strHobby = "";
  5. foreach (ListItem item in ListBox1.Items)
  6. {
  7.  
  8. if (item.Selected)
  9. {
  10. strHobby += item.Value + "";
  11.  
  12. }
  13. }
  14.  
  15. Label1.Text = strHobby;
  16. }

for循环

  1. protected void ListBox1_SelectedIndexChanged1(object sender, EventArgs e)
  2. {
  3. string strHobby = "";
  4. for (int i = ; i < ListBox1.Items.Count; i++)
  5. {
  6. if (ListBox1.Items[i].Selected)
  7. {
  8. strHobby += ListBox1.Items[i].Value ;
  9. }
  10. }
  11. Label1.Text = strHobby;
  12. }

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. php 判断是否get传值的参数是否存在

    if(is_array($_GET)&&count($_GET)>0)//先判断是否通过get传值了    {        if(isset($_GET["id&qu ...

  2. Java-集合类汇总

    结构图: Collection ├List │├LinkedList │├ArrayList │└Vector │ └Stack └Set Map ├Hashtable ├HashMap └WeakH ...

  3. request.getAttribute() 和 request.getParameter() 有何区别?

    HttpServletRequest类既有getAttribute()方法,也由getParameter()方法,这两个方法有以下区别: (1)HttpServletRequest类有setAttri ...

  4. Java编程思想学习(十一) 泛型

    1.概要 generics enable types (classes and interfaces) to be parameters when defining classes, interfac ...

  5. BZOJ-1067 降雨量 线段树+分类讨论

    这道B题,刚的不行,各种碎点及其容易忽略,受不鸟了直接 1067: [SCOI2007]降雨量 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 2859 ...

  6. UVA11400照明系统设计&& POJ1260Peals(DP)

    紫书P275: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=105116#problem/A POJ http://poj.org/pr ...

  7. android加载大图片到内存

    1)演示效果: 1)代码演示: 布局代码: 权限配置:

  8. PHP防止重复提交表单(helloweba网站经典实例)

    <?php session_start(); header("Content-Type:text/html;charset:utf8"); function set_toke ...

  9. Thinkphp中验证码的使用以及验证的实现

    <input class="TxtValidateCodeCssClass" id="captcha" name="captcha" ...

  10. Initialization of deep networks

    Initialization of deep networks 24 Feb 2015Gustav Larsson As we all know, the solution to a non-conv ...