zoukankan      html  css  js  c++  java
  • listbox 多选删除(找了好多都不行,终于让我写出来了)

    方法一:两个for循环

    aspx.cs

    private string id="";
    protected void btn_del_Click(object sender, EventArgs e)
    {

    for (int i = 0; i < typeList.Items.Count; i++)
    {
    if (typeList.Items[i].Selected)
    {
    id += typeList.Items[i].Value + ",";
    //id = string.Format("{0}{1},", id, typeList.Items[i].Value);
    }
    }
    id = id.Substring(0, id.Length - 1); //去掉最后一个“,”
    string[] arr = id.Split(',');
    for (int j = 0; j < arr.Length; j++)
    {
    int ii = Convert.ToInt32(arr[j]);
    B_MessageType.deleteMessageType(ii);
    }
    gettype();
    }

    方法二:少见的GetSelectedIndices();

    aspx.cs

    bool proper_selected = false;
    main_tips_container.Visible = false;
    if (lbTypeList.Items.Count > 0 )
    {

    int[] selTypes = lbTypeList.GetSelectedIndices();

    if (selTypes.Length > 0 )
    {
    proper_selected = true;
    for (int c = 0; c < selTypes.Length; c++)
    {
    string str_card_id = lbTypeList.Items[selTypes[c]].Value;
    int type_id = MyNumber.getInt(str_card_id);
    B_MessageType.deleteMessageType(type_id);

    }
    LoadTypeList();
    }
    }

    if (proper_selected == false)
    {
    main_tips_container.Visible = true;
    main_tips_body.InnerHtml = "Please check your type selection again !";
    }

    多多指教!

  • 相关阅读:
    poj--2031--Building a Space Station(prime)
    nyoj--364--田忌赛马(贪心)
    nyoj--496--巡回赛(拓扑排序)
    nyoj--1100--WAJUEJI which home strong!(bfs)
    hdoj--5625--Clarke and chemistry(枚举)
    poj--1753--Flip Game(dfs好题)
    poj--1101--The Game(bfs)
    冒泡排序
    php常见错误
    php乱码
  • 原文地址:https://www.cnblogs.com/suan1717/p/6215076.html
Copyright © 2011-2022 走看看