获取RadioButtonList每项数值 分别存进SQL数据库
publicSqlDataAdapterdab_tm(){//读取题目1SqlConnectionconn=GetConnection();if(conn.State==...
public SqlDataAdapter dab_tm()
{//读取题目1
SqlConnection conn = GetConnection();
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
SqlDataAdapter da = new SqlDataAdapter("select * from T_题目",conn);
DataSet ds=new DataSet();
da.Fill(ds,"timu");
return da;
conn.Close();
}
for (int i = 0; i <= 4;i++ )
{ new DB_con().dab_tm().Fill(ds,"timu");
Label lab = new Label();
RadioButtonList rlb = new RadioButtonList();
lab.ID = "lab" + i.ToString();
rlb.ID = "rlb" + i.ToString();
lab.Text = ds.Tables["timu"].Rows[i][1].ToString();
rlb.Items.Add(ds.Tables["timu"].Rows[i][2].ToString());
rlb.Items.Add(ds.Tables["timu"].Rows[i][3].ToString());
rlb.Items.Add(ds.Tables["timu"].Rows[i][4].ToString());
rlb.Items.Add(ds.Tables["timu"].Rows[i][5].ToString());
Panel1.Controls.Add(lab);
Panel1.Controls.Add(rlb);
rlb.DataBind();
}
有会的留下扣扣聊 我给分 展开
{//读取题目1
SqlConnection conn = GetConnection();
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
SqlDataAdapter da = new SqlDataAdapter("select * from T_题目",conn);
DataSet ds=new DataSet();
da.Fill(ds,"timu");
return da;
conn.Close();
}
for (int i = 0; i <= 4;i++ )
{ new DB_con().dab_tm().Fill(ds,"timu");
Label lab = new Label();
RadioButtonList rlb = new RadioButtonList();
lab.ID = "lab" + i.ToString();
rlb.ID = "rlb" + i.ToString();
lab.Text = ds.Tables["timu"].Rows[i][1].ToString();
rlb.Items.Add(ds.Tables["timu"].Rows[i][2].ToString());
rlb.Items.Add(ds.Tables["timu"].Rows[i][3].ToString());
rlb.Items.Add(ds.Tables["timu"].Rows[i][4].ToString());
rlb.Items.Add(ds.Tables["timu"].Rows[i][5].ToString());
Panel1.Controls.Add(lab);
Panel1.Controls.Add(rlb);
rlb.DataBind();
}
有会的留下扣扣聊 我给分 展开
1个回答
展开全部
RadioButtonList list1 = (RadioButtonList)Panel1.FindControl("rlb0");//第一个radiobuttonlist的 选项
if (list1 != null)
{
for (int i = 0; i < 4; i++)
{
if (list1.Items[i].Selected)
{
Label4.Text += list1.Items[i].Value.ToString(); //第一个 选项
break;
}
}
}
RadioButtonList list2 = (RadioButtonList)Panel1.FindControl("rlb1");//第二个radiobuttonlist的 选项,list2 名称不能和上一个重复
if (list2 != null)
{
for (int i = 0; i < 4; i++)
{
if (list2.Items[i].Selected)
{
Label4.Text += list2.Items[i].Value.ToString();// 第二个 选项
break;
}
}
}
if (list1 != null)
{
for (int i = 0; i < 4; i++)
{
if (list1.Items[i].Selected)
{
Label4.Text += list1.Items[i].Value.ToString(); //第一个 选项
break;
}
}
}
RadioButtonList list2 = (RadioButtonList)Panel1.FindControl("rlb1");//第二个radiobuttonlist的 选项,list2 名称不能和上一个重复
if (list2 != null)
{
for (int i = 0; i < 4; i++)
{
if (list2.Items[i].Selected)
{
Label4.Text += list2.Items[i].Value.ToString();// 第二个 选项
break;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询