CheckBoxList 用法强解

Code

改变成类通用

 #region  取复选框的值
    /// <summary>
    /// 取复选框的值
    /// </summary>
    /// <param name="ID">保存复选框的Value</param>
    /// <param name="Name">保存复选框的Text</param>
    /// <param name="CheckBoxListID">复选框ID</param>
    protected void SaveCheckBoxList(TextBox ID, TextBox Name, CheckBoxList CheckBoxListID)
    {
        string mID = string.Empty;
        string mName = string.Empty;
        for (int i = 0; i < CheckBoxListID.Items.Count; i++)//读取CheckBoxList 选中的值,保存起来
        {
            if (CheckBoxListID.Items[i].Selected)
            {
                mID += CheckBoxListID.Items[i].Value + "★";
                mName += CheckBoxListID.Items[i].Text + ",";
            }
        }
        if (!string.IsNullOrEmpty(mID))
        {
            ID.Text = mID.Substring(0, mID.Length - 1);
            Name.Text = mName.Substring(0, mName.Length - 1);
        }
        else
        {
            ID.Text = mID+"空";
            Name.Text = mName;
        }
    }
     #endregion

posted @ 2009-06-26 23:59  独修  阅读(541)  评论(0编辑  收藏  举报