日期:2014-05-18  浏览次数:20569 次

后台生成的【checkbox】怎么给name指定值
C# code

                Literal littxt = new Literal();
                Literal litti = new Literal();
                //CheckBoxList che = new CheckBoxList();//复选框多选择
                CheckBoxList cbk = new CheckBoxList();
                cbk.ID = "cbk" + i.ToString();
                
                littxt.Text = "<input type='hidden' name='db_" + bie.ToString() + "'  id='db_" + bie + "' value='' answer='" + Server.HtmlEncode(sdr["rightAns"].ToString()) + "'/>" + "<div class='result' id='result_" + bie.ToString() + "' >" + i.ToString() + "、" + Server.HtmlEncode(sdr["testContent"].ToString());
                litti.Text = "</div>";
                littcookie["littxt"] += HttpUtility.UrlEncode(littxt.Text + "|");
                littcookie["acbk"] += HttpUtility.UrlEncode(sdr["testAns1"].ToString()) + "|";
                littcookie["bcbk"] += HttpUtility.UrlEncode(sdr["testAns2"].ToString()) + "|";
                littcookie["ccbk"] += HttpUtility.UrlEncode(sdr["testAns3"].ToString()) + "|";
                littcookie["dcbk"] += HttpUtility.UrlEncode(sdr["testAns4"].ToString()) + "|";
                cbk.Items.Add("A. " + Server.HtmlEncode(sdr["testAns1"].ToString()));
                cbk.Items.Add("B. " + Server.HtmlEncode(sdr["testAns2"].ToString()));
                cbk.Items.Add("C. " + Server.HtmlEncode(sdr["testAns3"].ToString()));
                cbk.Items.Add("D. " + Server.HtmlEncode(sdr["testAns4"].ToString()));
                
                cbk.Font.Size = 11;
                for (int j = 1; j <= 4; j++)
                {
                    cbk.Items[j - 1].Value = j.ToString();
                    //cbk.Attributes["onclick"] = " db(1, "+i.ToString()+")";
                    cbk.Items[j - 1].Attributes.Add("onclick", " db(" + bie.ToString() + ", " + num++ + ")");//给input标签加事件
                    //cbk.Items[j - 1].Attributes.Add("name", " db" + bie.ToString() + "");//给input标签加事件
                }

                num = 1;
                bie++;
                Ans += sdr[6].ToString();
                if (Session["a"] == null)
                {
                    Session["Ans"] = Ans;
                }
                Panel1.Controls.Add(littxt);
                Panel1.Controls.Add(cbk);
                Panel1.Controls.Add(litti);
                i++;
                tNUM++;



HTML code
<tr>
                <td><input id="cbk9_0" type="checkbox" name="cbk9$0" onclick=" db(8, 1);" /><label for="cbk9_0">A. 氮质血症</label></td>
            </tr><tr>
                <td><input id="cbk9_1" type="checkbox" name="cbk9$1" onclick=" db(8, 2);" /><label for="cbk9_1">B. 高血糖</label></td>
            </tr><tr>
                <td><input id="cbk9_2" type="checkbox" name="cbk9$2" onclick=" db(8, 3);" /><label for="cbk9_2">C. 酮症</label></td>
            </tr><tr>
                <td><input id="cbk9_3" type="checkbox" name="cbk9$3" onclick=" d