簡單實現(xiàn)C# ListBox獲取多選項的值
作者:佚名
關于C# ListBox有好多方面要講,今天筆者為大家準備的是如何實現(xiàn)C# ListBox獲取多選項的值。
關于C# ListBox有好多方面要講,今天筆者為大家準備的是如何實現(xiàn)C# ListBox獲取多選項的值。
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- BindListBox();
- }
- }
- #region 綁定類別名稱到ListBox
- ///
- /// 綁定類別名稱到ListBox
- ///
- void BindListBox()
- {
- string sql = "SELECT * FROM ClassTable WHERE PlateID=2 OR PlateID=4";
- DataTable myClassTable = new ClassTable_bll().WhereToClassTable(sql);
- ListBox1.DataTextField = "MerchClassName";
- ListBox1.DataValueField = "ClassID";
- ListBox1.DataSource = myClassTable.DefaultView;
- ListBox1.DataBind();
- }
- #endregion
- protected void Button1_Click(object sender, EventArgs e)
- {
- string str = "";
- for (int i = 0; i < ListBox1.Items.Count; i++)
- {
- if (ListBox1.Items[i].Selected == true)
- {
- str = str + ListBox1.Items[i].Text+",";
- }
- }
- this.Response.Write("");
- }
以上就是關于C# ListBox獲取多選項的值的方法介紹。
【編輯推薦】
責任編輯:阡陌
來源:
網(wǎng)絡轉載