62,046
社区成员
发帖
与我相关
我的任务
分享
private void VotingData()
{
int[] m = new int[];
bool IsMult = false;
string strSql = "SELECT voitID,voitTitle FROM VoteItem";
string Vote_dns = WebConfigurationManager.ConnectionStrings["VoteConnectionString"].ToString();
SqlConnection conn = new SqlConnection(Vote_dns);
DataSet ds = new DataSet();
SqlDataAdapter sa = new SqlDataAdapter(strSql, conn);
sa.Fill(ds);
DataList1.DataSource = ds;
DataList1.DataBind();
conn.Open();
SqlCommand comm = new SqlCommand(strSql, conn);
using( SqlDataReader dr = comm.ExecuteReader())
{
while (dr.Read())
{
m.Add(dr.GetInt32(0));
}
}
for (int n = 1; n <= DataList1.Items.Count; n++)
{ //问题序号
Label lb = ((Label)DataList1.Items[n - 1].FindControl("lblTitle"));
lb.Text = n.ToString() + "、";
string strSqlChoice = "SELECT vochID,vochTitle FROM VoteChoice WHERE voitID=" + m[n-1];
SqlCommand chComm = new SqlCommand(strSqlChoice, conn);
SqlDataReader chDr = chComm.ExecuteReader(CommandBehavior.CloseConnection);
//多选,单选的不同显示
if (IsMult)
{
((CheckBoxList)DataList1.Items[0].FindControl("cbl")).Visible = true;
((CheckBoxList)DataList1.Items[0].FindControl("cbl")).DataSource = chDr;
((CheckBoxList)DataList1.Items[0].FindControl("cbl")).DataTextField = "vochTitle";
((CheckBoxList)DataList1.Items[0].FindControl("cbl")).DataValueField = "vochID";
((CheckBoxList)DataList1.Items[0].FindControl("cbl")).DataBind();
((RadioButtonList)DataList1.Items[0].FindControl("rbl")).Visible = false;
}
else
{
((RadioButtonList)DataList1.Items[0].FindControl("rbl")).Visible = true;
((RadioButtonList)DataList1.Items[0].FindControl("rbl")).DataSource = chDr;
((RadioButtonList)DataList1.Items[0].FindControl("rbl")).DataTextField = "vochTitle";
((RadioButtonList)DataList1.Items[0].FindControl("rbl")).DataValueField = "vochID";
((RadioButtonList)DataList1.Items[0].FindControl("rbl")).DataBind();
((CheckBoxList)DataList1.Items[0].FindControl("cbl")).Visible = false;
}
}
//显示答案选项
chDr.Close();
conn.Close();
}