一个字段保存多选,且后面还有“其他”

例如:心肌梗死部位:□前壁 □侧壁  下壁 后壁  右室  其他____

前台: <asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="0" RepeatLayout="Flow"></asp:CheckBoxList>

             <asp:TextBox ID="Teothers" runat="server" Width="100" MaxLength="200" CssClass="TextBoxLine" Visible="false"></asp:TextBox>

后台给控件添加选项:this.Teothers.Text = AddCheckBoxListItems(this.CheckBoxList1, shuzu, "");

提交:               

string tj= GetCheckBoxListValue(this.CheckBoxList1, this.Teothers);              

model.xinjigengsi = Common.regVerify.str(tj);

查看赋值:

string ck= FilterNullToEmpty(model.xinjigengsi);
this.Teothers.Text = AddCheckBoxListItems(this.CheckBoxList1, shuju, ck);

所需方法

方法1:public static string[] shuzu= {"前壁","侧壁","下壁","后壁","右室"};

方法2:

public static string AddCheckBoxListItems(ListControl cbl, string[] arrResource, string strAnalysis)
        {
            string strRtn = "";
            string str = FilterNullToEmpty(strAnalysis);
            int pos = str.LastIndexOf("|");

            if (pos >= 0)
            {
                strRtn = str.Substring(pos + 1);
                str = str.Substring(0, pos);
            }

            string[] str_array = str.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            int j = 0;

            for (int i = 0; i < arrResource.Length; i++)
            {
                string tmp = arrResource[i].Trim();

                if (string.IsNullOrEmpty(tmp))
                    continue;

                ListItem li = new ListItem(tmp, (i + 1).ToString());

                if (j < str_array.Length && (i + 1).ToString() == str_array[j])
                {
                    li.Selected = true;
                    j++;
                }
                cbl.Items.Add(li);
            }
            return strRtn;
        }

方法3:

public static string str(string str)
        {
            if (string.IsNullOrEmpty(str))
                return "";
            str = str.Replace("&", "&");
            str = str.Replace("<", "<");
            str = str.Replace(">", ">");
            str = str.Replace("'", "''");
            str = str.Replace("*", "");
            str = str.Replace("\r\n", "<br/>");
            str = str.Replace("\n", "<br/>");
            str = str.Replace("select", "");
            str = str.Replace("insert", "");
            str = str.Replace("update", "");
            str = str.Replace("delete", "");
            str = str.Replace("create", "");
            str = str.Replace("drop", "");
            str = str.Replace("exec", "");
            str = str.Replace("execute", "");
            str = str.Replace("db_name()", "");
            str = str.Replace("table", "");
            if (str.Trim().ToString() == "")
                str = "";
            return str;
        }

方法4:

public static string FilterNullToEmpty(string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return "";
            }
            else
            {
                return str;
            }
        }

方法5:

public static string GetCheckBoxListValue(CheckBoxList cbl, TextBox tb)
        {
            string strRtn = "";

            string str = "";

            for (int i = 0; i < cbl.Items.Count; i++)
            {
                if (cbl.Items[i].Selected)
                {
                    str += cbl.Items[i].Value + ",";
                }
            }

            if (!string.IsNullOrEmpty(str))
            {
                int len = str.Length;
                str = str.Substring(0, len - 1);
            }

            string str_others = tb.Text.Trim();

            if (!string.IsNullOrEmpty(str_others))
            {
                str += ("|" + str_others);
            }

            strRtn += str;

            return strRtn;
        }

.TextBoxLine
{
    padding: 5px 0px 0px 3px;
    border-width: 0px 0px 1px 0px;
    border-color: #EEEEEE;
    border-style: outset;
    background-color: #FFFFFF;
}





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值