zoukankan      html  css  js  c++  java
  • checklistbox的使用

    public class CheckListboxHelper
        {
            #region 为checklistbox绑定数据源
            /// <summary>
            /// 为checklistbox绑定数据源
            /// </summary>
            /// <typeparam name="T">数据源类型</typeparam>
            /// <param name="checklistbox">checklistbox对象</param>
            /// <param name="list">数据源</param>
            /// <param name="texfield">显示值字段名称</param>
            /// <param name="valuefield">值字段名称</param>
            public void CheckListboxDatabind<T>(CheckBoxList checklistbox, List<T> list, string texfield, string valuefield)
            {
                checklistbox.DataSource = list;
                checklistbox.DataTextField = texfield;
                checklistbox.DataValueField = valuefield;
                checklistbox.DataBind();
            }
            #endregion
    
            #region 获取checklistbox选中的值
            /// <summary>
            /// 获取checklistbox选中的值
            /// </summary>
            /// <param name="checklistbox">checklistbox对象</param>
            /// <returns>string字符串</returns>
            public string GetChecklistvalue(CheckBoxList checklistbox)
            {
                string listvalue = "";
                for (int i = 0; i < checklistbox.Items.Count; i++)
                {
    
                    if (checklistbox.Items[i].Selected)
                    {
                        listvalue = listvalue + checklistbox.Items[i].Value + ",";
                    }
                }
                listvalue = new StringHelper().ReplaceLastchar(listvalue, ",");
                return listvalue;
            }
            #endregion
    
            #region 设置checklistboxbox选中的值
            public void SetCheckListBoxChecked(CheckBoxList checklistbox, string checkvale)
            {
                string[] checkstrs;
                checkstrs = checkvale.Split(',');
                for (int i = 0; i < checklistbox.Items.Count; i++)
                {
                    for (int j = 0; j < checkstrs.Length; j++)
                    {
                        if (checklistbox.Items[i].Value == checkstrs[j])
                        {
    
                            checklistbox.Items[i].Selected = true;
                            break;
                        }
                    }
                }
            }
            #endregion
    
            #region 设置checkboxlist全选
            public void SetCheckListBoxAllChecked(CheckBox controlChecklistbox, CheckBoxList checklistbox)
            {
                for (int i = 0; i < checklistbox.Items.Count; i++)
                {
                    checklistbox.Items[i].Selected = controlChecklistbox.Checked;
                }
            }
            #endregion
        }

    今天要使用checklistboxbox,对其常用的方法进行了封装,有需要的朋友可以使用,也算是对自己写的东西的记录。

  • 相关阅读:
    poj1830 开关问题
    poj1681 Painter's Problem
    poj1222 EXTENDED LIGHTS OUT
    bzoj1923 [Sdoi2010]外星千足虫
    bzoj1013 [JSOI2008]球形空间产生器sphere
    poj2888 Magic Bracelet
    poj2409 Let it Bead
    poj1286 Necklace of Beads
    bzoj1004 HNOI2008 Cards
    bzoj2040 [2009国家集训队]拯救Protoss的故乡
  • 原文地址:https://www.cnblogs.com/lifengqi/p/4485041.html
Copyright © 2011-2022 走看看