简单实现C# ListBox获取多选项的值

开发 后端
关于C# ListBox有好多方面要讲,今天笔者为大家准备的是如何实现C# ListBox获取多选项的值。

关于C#  ListBox有好多方面要讲,今天笔者为大家准备的是如何实现C# ListBox获取多选项的值。

  1. protected void Page_Load(object sender, EventArgs e)  
  2.     {  
  3.         if (!IsPostBack)  
  4.         {  
  5.             BindListBox();  
  6.         }  
  7.     }  
  8.     #region 绑定类别名称到ListBox  
  9.     ///   
  10.     /// 绑定类别名称到ListBox  
  11.     /// 
  12.  
  13.     void BindListBox()  
  14.     {  
  15.         string sql = "SELECT * FROM ClassTable WHERE PlateID=2 OR PlateID=4";  
  16.         DataTable myClassTable = new ClassTable_bll().WhereToClassTable(sql);  
  17.         ListBox1.DataTextField = "MerchClassName";  
  18.         ListBox1.DataValueField = "ClassID";  
  19.         ListBox1.DataSource = myClassTable.DefaultView;  
  20.         ListBox1.DataBind();  
  21.     }  
  22.     #endregion  
  23.     protected void Button1_Click(object sender, EventArgs e)  
  24.     {  
  25.         string str = "";  
  26.         for (int i = 0; i < ListBox1.Items.Count; i++)  
  27.         {  
  28.             if (ListBox1.Items[i].Selected == true)  
  29.             {  
  30.                 str = str + ListBox1.Items[i].Text+",";                  
  31.             }  
  32.         }  
  33.         this.Response.Write("alert('" + str + "');");  
  34.     }  

以上就是关于C#  ListBox获取多选项的值的方法介绍。

【编辑推荐】

  1. 解析C# Socket编程实现访问网络的原理
  2. C# switch语句简单描述
  3. C# ServiceController类剖析
  4. C#抓取网页程序的实现浅析
  5. C#内存管理详细分析
责任编辑:阡陌 来源: 网络转载
相关推荐

2009-09-08 16:22:27

c# listBox

2009-09-11 11:58:00

C# ListBox多

2009-09-08 16:34:49

C# Listbox

2009-09-10 12:00:09

C# listbox

2009-09-08 15:12:07

C# ListBox

2009-08-12 15:50:40

C# ListBox

2009-08-19 11:21:02

C# ListBox控

2009-09-08 15:39:00

2009-08-14 14:19:50

Enhanced LiC#构建

2009-08-20 16:45:03

C#哈希值

2009-09-08 16:10:03

C# ListBox

2009-08-13 10:15:50

C#读取Excel

2009-09-07 15:27:04

C# MessageB

2009-09-08 17:37:54

C# listbox控

2009-09-08 14:54:40

C# listBox控

2009-09-02 14:33:57

C#类实现接口

2009-08-31 17:53:20

C#实现索引器

2009-09-08 09:31:54

c# CheckBox

2009-09-08 15:50:44

c# listbox

2009-08-25 11:13:28

C#获取逻辑硬盘信息
点赞
收藏

51CTO技术栈公众号