我正在从数据库中做随机问题,但现在我想存储值和问题 ID 并检查数据库查看天气答案是否正确?单击提交按钮后,如何存储单选按钮和文本框中的值?
这是我对随机问题的编码
public void showquestion()
{
string Category = "10-20";
string query = "SELECT top 10 * FROM question where Age_group= '"+ Category +"' order by newid()";
if (question.OpenConnection() == true)
{
SqlCommand comm = new SqlCommand(query, question.connection);
question.rdr = comm.ExecuteReader();
while (question.rdr.Read())
{
for (int j = 0; j < 1; j++)
{
HtmlTableRow row = new HtmlTableRow();
for (int i = 0; i < 1; i++)
{
HtmlTableCell cell = new HtmlTableCell();
Label label = new Label();
label.Text = Environment.NewLine + count + ") " + question.rdr["Question"].ToString();
label.ID = "Qustion_" + question.rdr["ID"].ToString() + "Label";
cell.Controls.Add(label);
row.Cells.Add(cell);
StoreQuestion[ArrayCount] = label.ID.ToString();
count++;
ArrayCount++;
}
table1.Rows.Add(row);
}
switch (Convert.ToInt32(question.rdr["question_type"]))
{
case 1:
Database question1 = new Database();
if (question1.OpenConnection() == true)
{
string query1 = "SELECT * FROM Choice WHERE Question_ID= " + question.rdr["id"];
SqlCommand comm1 = new SqlCommand(query1, question1.connection);
question1.rdr = comm1.ExecuteReader();
while (question1.rdr.Read())
{
for (int j = 0; j < 1; j++)
{
HtmlTableRow row = new HtmlTableRow();
for (int i = 0; i < 1; i++)
{
HtmlTableCell cell = new HtmlTableCell();
RadioButton radioButton = new RadioButton();
radioButton.Text = question1.rdr["Choice"].ToString();
radioButton.GroupName = question.rdr["Question"].ToString();
radioButton.ID = question.rdr["Question"].ToString() + question1.rdr["Choice"].ToString();
cell.Controls.Add(radioButton);
row.Cells.Add(cell);
}
table1.Rows.Add(row);
}
}
}
question1.CloseConnection();
break;
case 2://text box fill
for (int j = 0; j < 1; j++)
{
HtmlTableRow row = new HtmlTableRow();
for (int i = 0; i < 1; i++)
{
HtmlTableCell cell = new HtmlTableCell();
TextBox textbox = new TextBox();
textbox.ID = question.rdr["Question"].ToString();
cell.Controls.Add(textbox);
row.Cells.Add(cell);
}
table1.Rows.Add(row);
}
break;
}
}
question.CloseConnection();
protected void Submitbutton_Click(object sender, EventArgs e) {}
}
}