简单实现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获取多选项的值的方法介绍。

文章名称:简单实现C#ListBox获取多选项的值
分享路径:http://www.hantingmc.com/qtweb/news10/376810.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联