新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
簡(jiǎn)單實(shí)現(xiàn)C#ListBox獲取多選項(xiàng)的值
關(guān)于C# ListBox有好多方面要講,今天筆者為大家準(zhǔn)備的是如何實(shí)現(xiàn)C# ListBox獲取多選項(xiàng)的值。

- 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(" alert('" + str + "');");
- }
以上就是關(guān)于C# ListBox獲取多選項(xiàng)的值的方法介紹。
當(dāng)前名稱:簡(jiǎn)單實(shí)現(xiàn)C#ListBox獲取多選項(xiàng)的值
網(wǎng)站地址:http://www.dlmjj.cn/article/djeecec.html


咨詢
建站咨詢
