【CheckBoxList】 换成【CheckBox】 下面的代码该怎么修改
- C# code
SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { Literal littxt = new Literal(); Literal litti = new Literal(); //CheckBoxList che = new CheckBoxList();//复选框多选择 CheckBoxList cbk = new CheckBoxList(); littxt.Text = "<input type='hidden' name='db_" + bie.ToString() + "' id='db_" + bie + "' value='' answer='" + Server.HtmlEncode(sdr["rightAns"].ToString()) + "'/>" + "<div class='result' id='result_" + bie.ToString() + "' >" + i.ToString() + "、" + Server.HtmlEncode(sdr["testContent"].ToString()); litti.Text = "</div>"; littcookie["littxt"] += HttpUtility.UrlEncode(littxt.Text + "|"); littcookie["acbk"] += HttpUtility.UrlEncode(sdr["testAns1"].ToString()) + "|"; littcookie["bcbk"] += HttpUtility.UrlEncode(sdr["testAns2"].ToString()) + "|"; littcookie["ccbk"] += HttpUtility.UrlEncode(sdr["testAns3"].ToString()) + "|"; littcookie["dcbk"] += HttpUtility.UrlEncode(sdr["testAns4"].ToString()) + "|"; cbk.Items.Add("A. " + Server.HtmlEncode(sdr["testAns1"].ToString())); cbk.Items.Add("B. " + Server.HtmlEncode(sdr["testAns2"].ToString())); cbk.Items.Add("C. " + Server.HtmlEncode(sdr["testAns3"].ToString())); cbk.Items.Add("D. " + Server.HtmlEncode(sdr["testAns4"].ToString())); cbk.Font.Size = 11; for (int j = 1; j <= 4; j++) { cbk.Items[j - 1].Attributes.Add("onclick", " db(" + bie.ToString() + ", " + num++ + ")");//给input标签加事件 } num = 1; bie++; Ans += sdr[6].ToString(); if (Session["a"] == null) { Session["Ans"] = Ans; } cbk.Attributes.Remove("name"); Panel1.Controls.Add(littxt); Panel1.Controls.Add(cbk); Panel1.Controls.Add(litti); i++; tNUM++; }
------解决方案--------------------------------------------------------
那就只能这样啊
cbkA.Attributes.Add
cbkB.Attributes.Add
...
换成CheckBox不是好的做法
------解决方案--------------------------------------------------------
服务器控件就是这样的,就是取的话,你可以使用
document.getElementById("cbk").getElementsByTagName("input")
来进行遍历
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
$是系统生成的,不能去掉,你可以使用html的input实现,
$前面的内容都是一样的,可以知道哪些是一组的
------解决方案--------------------------------------------------------
你究竟要实现什么功能啊?在客户端js得到的方法很多啊,最简单的就是
allBox = document.getElementById("cbk").getElementsByTagName("input")