0

データベースからランダムな質問をしていますが、値と質問 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) {}
    }
}
4

1 に答える 1