您的位置:首页 > 其它

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

2014-02-19 14:25 471 查看
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" />

[b]当选择其它javascript显示隐藏TextBox[/b]

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


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

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);//药物过敏
}
[b]CheckBoxList的后台取使用,隔开的字符串,为前台的CheckBox赋值:[/b]
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);
}
}
}

[b][b]RadioButtonList[/b]的html代码:[/b]

<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>
当选择其它[b][b]javascript代码显示隐藏TextBox:[/b][/b]
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('');
}
});
}


[b][b]RadioButtonList[/b][/b][b]的后台取前台选择的RadioButton的值[/b]

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;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: