悬赏分:5 浏览:448 次
VS2005 的控件 checkbox 有多个选项,我想把选出来得值存入数据库中,
请问大家谁会啊??请尽快和我联系啊。。
eg: 比如说 table 表中 type 字段 是 varchar
页面上得类型是 类型: 飞机 大巴
怎样把页面上得值读出来插入数据库呢
|
checkbox.text 服务器控件就用foreach HTML控件就用request.form 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; } } } .aspx <input type='checkbox' name='cbType' value='typeValue' />text 。。。 .cs string cb=Request.Form['cbType'];//cb的值为“1,2,3”选择多个值将以逗号隔开 循环取.selected=true的值不就行了? 前台循环绑定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> <% } %> 代码太多发布不出来 美女就是受欢迎哦,这么多人抢肉 |
|
2个月前 冰儿 : 我的意思是谁会写前台和后太得代码啊。 给我一个例子让我看看也成啊 |
|
2个月前 飘忽忽的雲 : 我做的事一个简单的体检项目也就是一个TABLE 竖着的第一列显示人名 横着第一行显示体检的所有项目其他位置全是CHECBOX 体检哪项哪个就是挑。 |
|
2个月前 飘忽忽的雲 : 前台循环绑定 <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> <% } %> |
|
2个月前 飘忽忽的雲 : 后台从数据库读值 并给asp:Button 加一个JS的方法 using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; public partial class Relation2 : System.Web.UI.Page { DBaccess DBA = new DBaccess(); DataView DV = new DataView(); DataView DV1 = new DataView(); public DataView DV2 = new DataView(); public DataView DV3 = new DataView(); public int countuser; public int countitem; public int item = 0; public String[] indexs=new String[1000]; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { countuser = DBA.countuser(); countitem = DBA.countitems(); DV2 = DBA.selectitems(); DV3 = DBA.selectusers(); } } protected void btn_submit_Click(object sender, EventArgs e) { check(); notcheck(); } protected void btn_return_Click(object sender, EventArgs e) { string js = @"<Script language='JavaScript'> history.go({0}); </Script>"; HttpContext.Current.Response.Write(string.Format(js, -2)); } protected void check() { string id = hdf_id.Value; string[] ids = id.Split(','); for (int i = 0; i < ids.Length; i++) { insert(ids[i]); } } protected void insert(string id) { DV2 = DBA.selectitems(); DV3 = DBA.selectusers(); for (int i = 0; i < DBA.countuser(); i++) { for (int j = 1; j < DBA.countitems()+1; j++) { string index1 = "cbk_"; |
|
2个月前 飘忽忽的雲 : 代码太长了MS发不全 如果觉得对你有用的话可以给我邮箱我发给你,加我QQ也行不果上班时间不在QQ 49373976 |
|
2个月前 冰儿 : 嘿嘿谢谢大家的帮助。。我很开心。。呵呵 |