首页 新闻 会员 周边

checkbox 如何取值?

0
悬赏园豆:5 [已解决问题] 解决于 2008-08-26 08:03
<P>VS2005 的控件 checkbox 有多个选项,我想把选出来得值存入数据库中,</P> <P>请问大家谁会啊??请尽快和我联系啊。。</P> <P>eg: 比如说 table 表中 type 字段 是 varchar </P> <P>页面上得类型是 类型: 飞机&nbsp;&nbsp;大巴</P> <P>怎样把页面上得值读出来插入数据库呢&nbsp; </P>
冰儿的主页 冰儿 | 初学一级 | 园豆:200
提问于:2008-08-25 09:53
< >
分享
最佳答案
0
感觉你这个应该是多选吧, 为什么不用CheckboxList控件呢 页面: 添加了CheckBoxList 控件和一个Button控件 <asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatDirection="Horizontal"> <asp:ListItem>飞机</asp:ListItem> <asp:ListItem>坦克</asp:ListItem> <asp:ListItem>大巴</asp:ListItem> </asp:CheckBoxList> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> 代码: 在Button的Click事件中遍历的CheckBoxList的Itme protected void Button1_Click(object sender, EventArgs e) { ArrayList al = new ArrayList(); for (int i = 0; i < this.CheckBoxList1.Items.Count; i++) { if (this.CheckBoxList1.Items[i].Selected) { al.Add(this.CheckBoxList1.Items[i].Value); } } }
程序员老李 | 小虾三级 |园豆:790 | 2008-08-25 10:24
其他回答(7)
0
checkbox.text
小眼睛老鼠 | 园豆:2731 (老鸟四级) | 2008-08-25 09:56
0
服务器控件就用foreach HTML控件就用request.form
丁学 | 园豆:18730 (专家六级) | 2008-08-25 09:58
0
foreach (string s in Request.Form.AllKeys) { controlId = "cb" + strRID; if (s.Substring(s.Length - controlId.Length, controlId.Length) == controlId) { if (Request.Form[s] == "on") { //dv[i]["State"] = 1; state = true; } } }
绝版色狼 | 园豆:318 (菜鸟二级) | 2008-08-25 10:31
0
.aspx <input type='checkbox' name='cbType' value='typeValue' />text 。。。 .cs string cb=Request.Form['cbType'];//cb的值为“1,2,3”选择多个值将以逗号隔开
wsky | 园豆:558 (小虾三级) | 2008-08-25 12:10
0
循环取.selected=true的值不就行了?
有所为,有所不为 | 园豆:1200 (小虾三级) | 2008-08-25 14:03
0
前台循环绑定HTML控件 <script language="javascript" type="text/javascript"> function aaa() { var s=""; var v=""; var n=""; var index1="cbk_"; s=document.getElementsByName("qq"); for(var x=0;x<s.length;x++) { if(s[x].checked==true) { v=v+s[x].value+","; } else { n=n+s[x].value+","; } } document.getElementById("hdf_id").value=v; document.getElementById("hdf_nid").value=n; // document.write(w); // document.write(d); } </script> </head> <body> <form id="form1" runat="server"> <div> <table> <tr> <td></td> <td></td> </tr> </table> <table> <tr> <td>Username</td> <% DBaccess DBA = new DBaccess(); int counti = DBA.countitems(); DV2 = DBA.selectitems(); DV3 = DBA.selectusers(); for (int i = 0; i < counti; i++) { %> <td><%=HttpUtility.HtmlAttributeEncode(DV2[i]["itemname"].ToString())%></td> <% } %> </tr> <% int countu = DBA.countuser(); for (int i = 0; i < countu; i++) { %> <tr> <% for (int j = 0; j < counti + 1; j++) { %> <% if (j == 0) { %> <td><label><%=HttpUtility.HtmlAttributeEncode(DV3[i]["username"].ToString())%></label></td> <% } %> 代码太多发布不出来
hghsdf | 园豆:165 (初学一级) | 2008-08-25 15:17
0
美女就是受欢迎哦,这么多人抢肉
zjy | 园豆:3194 (老鸟四级) | 2008-08-25 16:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册