asp.net 做简单的动态有奖调查

后台从数据库里读出数据并按格式现实:显示问题和答案的时候 标签格式固定 有问题编号 选项序号

protected void InfoBind()

    {

        Ds = upays.Function_ReturnDataSet(CommandType.Text, "select * from Survey_Title where Tid=" + Convert.ToInt32(Request.QueryString["id"]));

        if (Ds != null && Ds.Tables[0].Rows.Count == 1)

        {

            Title = Ds.Tables[0].Rows[0]["Title"].ToString();

            Tpic = Ds.Tables[0].Rows[0]["Tpic"].ToString();

            Tcontent = Ds.Tables[0].Rows[0]["Tcontent"].ToString();

            StartTime = Ds.Tables[0].Rows[0]["StartTime"].ToString();

            EndTime =Convert.ToDateTime(Ds.Tables[0].Rows[0]["EndTime"].ToString());

            AddTime = Ds.Tables[0].Rows[0]["AddTime"].ToString();

            CountNum = Ds.Tables[0].Rows[0]["CountNum"].ToString();

            SurveyNum = Ds.Tables[0].Rows[0]["SurveyNum"].ToString();

            if (DateTime.Compare(EndTime, DateTime.Now) < 0 )

            {



                Page.RegisterStartupScript("","<script>alert('该调查已经结束');</script>");

                submit.Enabled = false;

            }

            if (CountNum == SurveyNum)

            {

                Page.RegisterStartupScript("", "<script>alert('该调查已经结束');</script>");

                submit.Enabled = false;

            }

           

        }



        InfoAll = "<div class=\" ml30 cycsurveyie6 mt10\">";





        Ds = upays.Function_ReturnDataSet(CommandType.Text, "select * from Survey_Question sq where sq.Tid="+Convert.ToInt32(Request.QueryString["id"]));

        if(Ds!=null&&Ds.Tables[0].Rows.Count>0)

        {

            for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)

            {

                Ds2 = upays.Function_ReturnDataSet(CommandType.Text, "select * from Survey_Answer sa where Qid="+Convert.ToInt32(Ds.Tables[0].Rows[i]["Qid"].ToString()));



               



                    if (Ds.Tables[0].Rows[i]["Qtype"].ToString() == "1")

                    {

                        InfoType += "<div class=\"fleft w128 hide cycfchei\" style=\"float:left; clear:both; margin-top:20px;\" ><span style=\"font-size:15px;\">" + Convert.ToString(i + 1) + "、" + Ds.Tables[0].Rows[i]["Question"].ToString() + "</span></br>";

                    }



                    if (Ds.Tables[0].Rows[i]["Qtype"].ToString() == "2")

                    {

                        InfoType += "<div class=\"fleft w128 hide cycfchei\" style=\"float:left; clear:both; margin-top:20px;\"><span style=\"font-size:15px;\">" +Convert.ToString(i+1)+"、"+Ds.Tables[0].Rows[i]["Question"].ToString() + "</span></br>";

                    }



                    if (Ds.Tables[0].Rows[i]["Qtype"].ToString() == "3")

                    {

                        InfoType += " <div class=\"fleft ft14 cycfchei lh25\" style=\"float:left; clear:both; margin-top:20px;\"><span style=\"font-size:15px;\">" + Convert.ToString(i + 1) + "、" + Ds.Tables[0].Rows[i]["Question"].ToString() + "</span></br>";

                    }

                



                for (int j = 0; j < Ds2.Tables[0].Rows.Count; j++)

                {

                    if (Ds.Tables[0].Rows[i]["Qtype"].ToString() == "1")

                    {

                        InfoType += "<input name=\"ra" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "\" type=\"radio\" id=\"ra_" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "_" + Ds2.Tables[0].Rows[j]["Cid"].ToString() + "\" >" + Ds2.Tables[0].Rows[j]["Citem"].ToString()+" ";

                    }



                    if (Ds.Tables[0].Rows[i]["Qtype"].ToString() == "2")

                    {

                        InfoType += "<input name=\"cb" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "\" type=\"checkbox\" id=\"cb_" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "_" + Ds2.Tables[0].Rows[j]["Cid"].ToString() + "\" >" + Ds2.Tables[0].Rows[j]["Citem"].ToString() + " ";

                    }



                    

                }

                if (Ds.Tables[0].Rows[i]["Qtype"].ToString() == "3")

                {

                    InfoType += "<input name=\"text" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "\" type=\"text\" id=\"text_" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "\" >";

                }



                InfoType += "</div></br></br>";

            }

        }



        InfoAll += InfoType;

        InfoAll += "</div>";

    }

 

 

前台js存储答案:

<script language="javascript" type="text/javascript">

    function InfoGet()

    {

        //var Element=document.getElementsByTagName("INPUT");

        var mainDetails=document.getElementById("mainDetails");

        var Element=mainDetails.getElementsByTagName("INPUT");

        var hides=document.getElementById("hide");

        for(var i=0;i<Element.length;i++)

        {

            if(Element[i].type=="radio")

            {

                if(Element[i].checked)

                {

                    hides.value+=Element[i].id+"@";

                }

            }

            if(Element[i].type=="checkbox")

            {

                if(Element[i].checked)

                {

                    hides.value+=Element[i].id+"@";

                }

            }

            if(Element[i].type=="text")

            {

                if(Element[i].value!="")

                {

                    hides.value+=Element[i].id+"$"+Element[i].value+"@";

                }

            }

        }

    }

</script>

 

 

查看单个调查结果 根据数据库里用户选择的标签id 进行选择:

 

if (Ds != null && Ds.Tables[0].Rows.Count > 0)

        {

            for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)

            {

                Ds2 = upays.Function_ReturnDataSet(CommandType.Text, "select * from Survey_Answer sa where Qid=" + Convert.ToInt32(Ds.Tables[0].Rows[i]["Qid"].ToString()));



 



                if (Ds.Tables[0].Rows[i]["Qtype"].ToString() == "1")

                {

                    InfoType += "<div class=\"fleft w128 hide cycfchei\" style=\"float:left; clear:both; margin-top:20px;\" ><span style=\"font-size:15px;\">" + Convert.ToString(i + 1) + "、" + Ds.Tables[0].Rows[i]["Question"].ToString() + "</span></br>";

                }



                if (Ds.Tables[0].Rows[i]["Qtype"].ToString() == "2")

                {

                    InfoType += "<div class=\"fleft w128 hide cycfchei\" style=\"float:left; clear:both; margin-top:20px;\"><span style=\"font-size:15px;\">" + Convert.ToString(i + 1) + "、" + Ds.Tables[0].Rows[i]["Question"].ToString() + "</span></br>";

                }



                if (Ds.Tables[0].Rows[i]["Qtype"].ToString() == "3")

                {

                    InfoType += " <div class=\"fleft ft14 cycfchei lh25\" style=\"float:left; clear:both; margin-top:20px;\"><span style=\"font-size:15px;\">" + Convert.ToString(i + 1) + "、" + Ds.Tables[0].Rows[i]["Question"].ToString() + "</span></br>";

                }





                for (int j = 0; j < Ds2.Tables[0].Rows.Count; j++)

                {

                    if (Ds.Tables[0].Rows[i]["Qtype"].ToString() == "1")

                    {

                        if (Content.IndexOf("ra_" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "_" + Ds2.Tables[0].Rows[j]["Cid"].ToString()) >= 0)

                        {

                            InfoType += "<input name=\"ra" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "\"  checked=\"checked\" runat=\"server\" type=\"radio\" id=\"ra_" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "_" + Ds2.Tables[0].Rows[j]["Cid"].ToString() + "\" >" + Ds2.Tables[0].Rows[j]["Citem"].ToString() + " ";

                        }

                        else

                        {

                            InfoType += "<input name=\"ra" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "\" runat=\"server\" type=\"radio\" id=\"ra_" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "_" + Ds2.Tables[0].Rows[j]["Cid"].ToString() + "\" >" + Ds2.Tables[0].Rows[j]["Citem"].ToString() + " ";

                        }

                        

                    }



                    if (Ds.Tables[0].Rows[i]["Qtype"].ToString() == "2")

                    {

                        if (Content.IndexOf("cb_" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "_" + Ds2.Tables[0].Rows[j]["Cid"].ToString()) >= 0)

                        {

                            InfoType += "<input name=\"cb" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "\" checked=\"checked\" runat=\"server\" type=\"checkbox\" id=\"cb_" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "_" + Ds2.Tables[0].Rows[j]["Cid"].ToString() + "\" >" + Ds2.Tables[0].Rows[j]["Citem"].ToString() + " ";

                        }

                        else

                        {

                            InfoType += "<input name=\"cb" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "\" runat=\"server\" type=\"checkbox\" id=\"cb_" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "_" + Ds2.Tables[0].Rows[j]["Cid"].ToString() + "\" >" + Ds2.Tables[0].Rows[j]["Citem"].ToString() + " ";

                        }



                    }





                }

                if (Ds.Tables[0].Rows[i]["Qtype"].ToString() == "3")

                {

                    if (Content.IndexOf("text_" + Ds.Tables[0].Rows[i]["Qid"].ToString()) >= 0)

                    {

                        string Copy = Content.Substring(Content.IndexOf("text_" + Ds.Tables[0].Rows[i]["Qid"].ToString()) + 1, Content.Length - Content.IndexOf("text_" + Ds.Tables[0].Rows[i]["Qid"].ToString()) - 1);

                        int startIndex = Copy.IndexOf("$");

                        int endIndex = Copy.IndexOf("@");

                        Copy = Copy.Substring(startIndex+1, endIndex - startIndex-1);

                        InfoType += "<input name=\"text" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "\" runat=\"server\" type=\"text\" id=\"text_" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "\" value=\"" + Copy + "\" >";

                    }

                    else

                    {

                        InfoType += "<input name=\"text" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "\" runat=\"server\" type=\"text\" id=\"text_" + Ds.Tables[0].Rows[i]["Qid"].ToString() + "\" >";

                    }

                }



                InfoType += "</div></br></br>";

            }

        }



        InfoAll += InfoType;

        InfoAll += "</div>";



       

    }

 

你可能感兴趣的:(asp.net)