zoukankan      html  css  js  c++  java
  • CheckBoxList和RadioButtonList的使用(后台取值和赋值)

    CheckBoxList的html代码:
                                <asp:CheckBoxList ID="cblstYWGM" runat="server" RepeatDirection="Horizontal">
                                </asp:CheckBoxList>
                                <asp:CheckBox ID="cboxYWGM" Text="其它" runat="server" />
                                <asp:TextBox ID="txtGMQT" runat="server" />
    

    当选择其它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代码:

                                    <asp:RadioButtonList ID="rbtlstYszt" runat="server" RepeatDirection="Horizontal">
                                        <asp:ListItem Text="清醒" />
                                        <asp:ListItem Text="模糊" />
                                        <asp:ListItem Text="瞻望或烦躁" />
                                        <asp:ListItem Text="其它" />
                                    </asp:RadioButtonList>
                                    <asp:TextBox ID="txtYszt" runat="server" />
                                    <asp:RequiredFieldValidator ForeColor="Red" ID="RequiredFieldValidator1" runat="server"
                                        ControlToValidate="rbtlstYszt" ErrorMessage="*"></asp:RequiredFieldValidator>
    当选择其它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;
                        }
                    }
                }

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

  • 相关阅读:
    URAL1996 Cipher Message 3(KMP + FFT)
    UVa12633 Super Rooks on Chessboard(容斥 + FFT)
    SPOJ TSUM Triple Sums(FFT + 容斥)
    UVa12298 Super Poker II(母函数 + FFT)
    LA4671 K-neighbor substrings(FFT + 字符串Hash)
    HDU4080 Stammering Aliens(二分 + 后缀数组)
    HDU4609 3-idiots(母函数 + FFT)
    HDU1402 A * B Problem Plus(FFT)
    快速傅里叶变换FFT学习小记
    HDU4971 A simple brute force problem.(强连通分量缩点 + 最大权闭合子图)
  • 原文地址:https://www.cnblogs.com/ful1021/p/4804441.html
Copyright © 2011-2022 走看看