CheckBoxList和RadioButtonList的使用(后台取值和赋值)
2014-02-19 14:25
471 查看
CheckBoxList的html代码:
[b]当选择其它javascript显示隐藏TextBox[/b]
[b]CheckBoxList的后台取前台选择的CheckBox的值,使用,隔开:[/b]
[b][b]RadioButtonList[/b]的html代码:[/b]
[b][b]RadioButtonList[/b][/b][b]的后台取前台选择的RadioButton的值[/b]
<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; } } }
相关文章推荐
- BindProvider
- 【java初学笔记3】马士兵-java-面向对象-34->36-Object类的问题
- 陷波滤波器
- CheckBoxList和RadioButtonList的使用(后台取值和赋值)
- .NET开发笔记(二十三) 谷歌地图下载
- 前瞻设计:创新型战略推动可持续变革(全彩)
- Android NFC 标签分发系统小析
- java类加载器
- 控件(3)ListView
- Linux设备驱动之I2C架构分析【转】
- iOS7控键变化及页面效果
- 修改Oracle SYS,SYSTEM密码以及认证口令和认证方式
- showModalDialog后如何刷新父页面
- JDK 内置工具 jstack,javah,jps,jstat,jmap,jinfo,jconsole,jhat,jdb,jvisualvm 的作用和使用
- 控件(2)toast
- 用saltstack cp模块实现文件管理、拉取和回滚下发 推荐
- Valgrind 使用简单说明
- 查看组所属管理包
- Linux DNS
- 解压eep封闭包文件