首页 新闻 会员 周边 捐助

动态生成几个checkboxlist,取值问题!

0
悬赏园豆:40 [已解决问题] 解决于 2016-11-08 10:45

多选题

CheckBoxList cbl = new CheckBoxList();
cbl.ID = "cbl" + j.ToString();//int j=1;
littxt.Text = j.ToString() + "、" + Server.HtmlEncode(dr2["Title"].ToString()) + "<br>";
cbl.Items.Add("A. " + Server.HtmlEncode(dr2["AnswerA"].ToString()));
cbl.Items.Add("B. " + Server.HtmlEncode(dr2["AnswerB"].ToString()));
cbl.Items.Add("C. " + Server.HtmlEncode(dr2["AnswerC"].ToString()));
cbl.Items.Add("D. " + Server.HtmlEncode(dr2["AnswerD"].ToString()));
cbl.Font.Size = 11;

cbl.Items[0].Value = "A";
cbl.Items[1].Value = "B";
cbl.Items[2].Value = "C";
cbl.Items[3].Value = "D";

Panel1.Controls.Add(littxt);
Panel1.Controls.Add(cbl);
j++;

}

 

foreach (Control c in Panel1.Controls)
{
if (c is CheckBoxList)
{
m2++;//m2=0;
}
}
string getvalue2 = null;
for (int i = 1; i < m2; i++)
{

if (((CheckBoxList)Panel1.FindControl("cbl" + i.ToString())).Items[i-1].Selected==true)
{

getvalue2 += ((CheckBoxList)Panel1.FindControl("cbl" + i.ToString())).Items[i - 1].Value+",";
//}

if (getvalue2 == null || getvalue2.Equals(""))
{
getvalue2 = "X";
}
string str3 = "insert into Answer values......."

我取到的值有问题,而且每个CheckBoxList)的getvalue2都是在前一个之上加的

mmypdf的主页 mmypdf | 初学一级 | 园豆:134
提问于:2014-05-29 08:56
< >
分享
最佳答案
0

看到你的标题,原本我不想回,

既然打开,我告诉你,能不能不要围着服务端控件玩命

收获园豆:40
[秦时明月] | 小虾三级 |园豆:738 | 2014-05-29 16:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册