• 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,对其常用的方法进行了封装,有需要的朋友可以使用,也算是对自己写的东西的记录。

  • 相关阅读:
    nil指针判断
    不使用slice作为函数入参
    log4php
    Results gofmt 0% go_vet 100% gocyclo 97% golint 100% ineffassign 97% license 100% misspell 100%
    获取点击元素的文本信息 复制到剪切板 监听鼠标悬浮
    磁盘IO
    copylocks
    sh: 1: node: Permission denied
    白盒代码审计
    升级基础
  • 原文地址:https://www.cnblogs.com/lifengqi/p/4485041.html
Copyright © 2020-2023  润新知