List动态加载Rdblist
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.Collections.Generic;
public partial class List : System.Web.UI.Page
{
public static int I = 0;
protected void Page_Load(object sender, EventArgs e)
{
bind();
}
void bind()
{
//获取所有选择题
List<Marlboro.Model.Qu> lt = new List<Marlboro.Model.Qu>();
lt = new Marlboro.BLL.T_Qu().Rt_qu();
//获取所有答案
List<Marlboro.Model.Answer> lt_A = new List<Marlboro.Model.Answer>();
lt_A = new Marlboro.BLL.T_Answer().Rt_answer();
for (int i = 0; i < lt.Count; i++)
{
Label lblqu = new Label();
lblqu.Text = "第" + lt[i].Q_ID.ToString() + "题:<br>" + lt[i].Q_Name.ToString() + Str(lt[i].Q_Type) + "<br>";
this.Label1.Controls.Add(lblqu);
RadioButtonList rdblist = new RadioButtonList();
rdblist.AutoPostBack = false;
rdblist.ID = "rdblist" + i;
for (int j = 0; j < lt_A.Count; j++)
{
if (lt_A[j].Q_ID == lt[i].Q_ID)
{
rdblist.Items.Add(new ListItem(lt_A[j].A_Content.ToString(), lt_A[j].A_Value.ToString()));
}
}
this.Label1.Controls.Add(rdblist);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
}
public string Str(int a)
{
if (a == 1)
{
return "〓单选〓";
}
return "";
}
protected void Button2_Click(object sender, EventArgs e)
{
int count = Convert.ToInt32(this.Label1.Controls.Count) / 2;
int value = 0;
for (int i = 0; i < count; i++)
{
RadioButtonList rdblsit = (RadioButtonList)this.Label1.FindControl("rdblist" + i);
for (int j = 0; j < rdblsit.Items.Count; j++)
{
if (rdblsit.Items[j].Selected)
{
value += Convert.ToInt32(rdblsit.Items[j].Value);
}
}
}
Response.Write(value);
}
protected void Pager_PageChanged(object sender, EventArgs e)
{
}
}