-1

オブジェクトタイプ(droprdown、checkbox、radioutton ..)に基づいてdbテーブルから質問を入力する私のコードは次のとおりです。

  if (str.Trim().ToLower() == "dropdown box")
            {
                string[] strArr = strOptions.Split('|');
                DropDownList ddl = new DropDownList();
                ddl.ID = "ddl";
                ddl.CssClass = "CheckBox";
                ddl.Width = Unit.Pixel(100);
                // ddl.Items.Add(new ListItem("test", "test"));

                if (strArr.Count() > 0)
                {
                    foreach (string s in strArr)
                    {

                        ddl.Items.Add(new ListItem(s, s));

                    }
                }
                else
                {
                    ddl = new DropDownList();
                    ddl.ID = "ddlContent1";
                    ddl.Width = Unit.Pixel(150);
                    plc.Controls.Add(ddl);
                }
                plc.Controls.Add(ddl);
            }
            if (str.Trim().ToLower() == "checkbox list")
            {

                string[] strArr = strOptions.Split('|');

                if (strArr.Count() > 0)
                {
                    foreach (string s in strArr)
                    {
                        CheckBox chk = new CheckBox();

                        chk.ID = s;
                        chk.Text = s;
                        chk.CssClass = "CheckBox";

                        if (strFooterOptions == "If all of the above are checked, please SUBMIT.  [Click here to Submit]")
                            chk.Attributes.Add("onclick", "checkAllCheckBox()");
                        plc.Controls.Add(chk);
                        plc.Controls.Add(new LiteralControl("<br />"));

                    }

                }

そして私の前と次のボタン、あなたが次に押すと、別のセクションに別の質問が表示されます。

 protected void btnNext_Click(object sender, EventArgs e)
    {
        // int section = 1;

        section = section + 1;
        btnPrev.Enabled = true;
        FillSection();

    }
    protected void btnPrev_Click(object sender, EventArgs e)
    {

            section = section - 1;
            FillSection();

    }

次にヒットしたときにデータベースに応答を挿入するメソッドを作成するにはどうすればよいですか? どんなアイデアでも感謝します

ありがとう

4

1 に答える 1

0

調査オプションをどのように保存するかによって異なります。同様のことを行い、すべてのオプションをデータベースの同じ行に保存しました。最初に、どの調査が行われたかを保存するための Cookie を作成しました (例: すべての都市のページに調査があり、ロンドンが行われました)。次に、db を実行する関数を作成しました。

IF NOT EXISTS (Select * from your_survey_table where column=cookievalue) 
INSERT INTO your_survey_table (your_columns_here) VALUES (@your_values) 
ELSE 
UPDATE your_survey_table SET option2=@your_value
于 2013-07-24T11:37:53.407 に答える