CheckBoxList和RadioButtonList的使用(后台取值和赋值)

CheckBoxList和RadioButtonList的使用(后台取值和赋值)

CheckBoxList的html代码:

当选择其它javascript显示隐藏TextBox

        function cbQiTaShowHide() {
            var txtId = "txtGMQT";
            var cbid = "cboxYWGM";
            $("#" + txtId).hide();
            $("#" + cbid).change(function () {
                if ($("#" + cbid).attr("checked")) {
                    $("#" + txtId).show();
                } else {
                    $("#" + txtId).hide();
                    $("#" + txtId).val('');
                }
            });
        }

CheckBoxList的后台取前台选择的CheckBox的值,使用,隔开:

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < cblstYWGM.Items.Count; i++)
            {
                if (cblstYWGM.Items[i].Selected == true)
                {
                    sb.AppendFormat("{0},", cblstYWGM.Items[i].Text);
                }
            }
            if (cboxYWGM.Checked && !string.IsNullOrWhiteSpace(txtGMQT.Text.Trim()))
            {
                sb.AppendFormat("{0}q,", txtGMQT.Text.Trim());
            }
            if (sb.Length > 1)
            {
                info.DrugAllergy = sb.ToString().Substring(0, sb.Length - 1);//药物过敏
            }
CheckBoxList的后台取使用,隔开的字符串,为前台的CheckBox赋值:
                if (!string.IsNullOrWhiteSpace(info.DrugAllergy))
                {
                    string[] strs = info.DrugAllergy.Split(',');
                    foreach (var s in strs)
                    {
                        for (int i = 0; i < cblstYWGM.Items.Count; i++)
                        {
                            if (cblstYWGM.Items[i].Text == s)
                            {
                                cblstYWGM.Items[i].Selected = true;
                            }
                        }
                        if (s.Length > 1 && s.Substring(s.Length - 1) == "q")
                        {
                            cboxYWGM.Checked = true;
                            txtGMQT.Visible = true;
                            txtGMQT.Text = s.Substring(0, s.Length - 1);
                        }
                    }
                }

RadioButtonList的html代码:

当选择其它javascript代码显示隐藏TextBox:
        function rbtQiTaShowHide() {
            var id = "rbtlstYszt";
            var txtId = "txtYszt";
            $("#" + txtId).hide();
            $("input[name=" + id + "]").change(function () {
                if ($("input[name=" + id + "][value=其它]").attr("checked") == "checked") {
                    $("#" + txtId).show();
                } else {
                    $("#" + txtId).hide();
                    $("#" + txtId).val('');
                }
            });
        }

RadioButtonList后台取前台选择的RadioButton的值

            for (int i = 0; i < rbtlstYszt.Items.Count; i++)
            {
                if (rbtlstYszt.Items[i].Selected == true)
                {
                    if (rbtlstYszt.Items.FindByText("其它").Selected)
                    {
                        info.YSZT = txtYszt.Text.Trim();//意识状态
                    }
                    else
                    {
                        info.YSZT = rbtlstYszt.SelectedItem.Text;
                    }
                }
            }

版权声明:本文为博主原创文章,未经博主允许不得转载。