多选题
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都是在前一个之上加的
看到你的标题,原本我不想回,
既然打开,我告诉你,能不能不要围着服务端控件玩命