本文介绍了我正在尝试将部分面板转换为pdf,我将其作为占位符中的参考传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if (dtSection.Rows.Count > 0)
                            {
                                foreach (DataRow row in dtSection.Rows)
                                {
                                    int SectionID = Convert.ToInt32(row["SectionID"]);

                                    DataTable dtQuestion = Code.GetQuestionBySectionID(SectionID);
                                    DataTable dtAnswer = Code.GetStudAnswerBySectionID(SectionID, PlanID, CWID);
                                    string itemAnswer = "";
                                    int itemAnswerID = 0;

                                    if (dtQuestion.Rows.Count > 0)
                                    {
                                        Panel sectionPanel = new Panel();
                                        sectionPanel.ID = string.Format("FieldSet_{0}", SectionID);
                                        //sectionPanel.BorderStyle = BorderStyle.Solid;
                                        //sectionPanel.BorderWidth = 1;
                                        sectionPanel.GroupingText = string.Format("{0}", row["Note"]);
                                        sectionPanel.CssClass = "ExtraPanel";

                                        foreach (DataRow qRow in dtQuestion.Rows)
                                        {
                                            int QuestionID = Convert.ToInt32(qRow["QuestionID"]);
                                            //Check if the answer has been entered
                                            if (dtAnswer.Rows.Count > 0)
                                            {
                                                for (int index = 0; index < dtAnswer.Rows.Count; index++)
                                                {
                                                    //if the answer is matching with the questionid, then there is anwer to this question
                                                    if (Convert.ToInt32(dtAnswer.Rows[index]["QuestionID"].ToString()) == QuestionID)
                                                    {
                                                        itemAnswer = dtAnswer.Rows[index]["Answer"].ToString();
                                                        if (!string.IsNullOrWhiteSpace(dtAnswer.Rows[index]["AnswerItemID"].ToString()))
                                                        {
                                                            itemAnswerID = Convert.ToInt32(dtAnswer.Rows[index]["AnswerItemID"].ToString());
                                                        }
                                                        else
                                                        {
                                                            itemAnswerID = 0;
                                                        }
                                                    }
                                                }
                                            }

                                            int qType = Convert.ToInt32(qRow["QuestTypeID"]);

                                            switch (qType)
                                            {
                                                case 1: //single choice - checkbox
                                                    CheckBox chbQuest = new CheckBox();
                                                    chbQuest.ID = string.Format("CheckBox_{0}", qRow["QuestionID"]);
                                                    chbQuest.Text = qRow["Question"].ToString();

                                                    if (!string.IsNullOrEmpty(itemAnswer))
                                                    {
                                                        chbQuest.Checked = Boolean.Parse(itemAnswer);
                                                    }
                                                    sectionPanel.Controls.Add(chbQuest);
                                                    sectionPanel.Controls.Add(new LiteralControl("<br>"));
                                                    sectionPanel.Controls.Add(new LiteralControl("<br>"));
                                                    break;
                                                case 2:		// multiple choices
                                                    RadioButtonList rblQuetItem = new RadioButtonList();
                                                    DataTable dtQuestItem = Code.GetQuestionItemByQuestionID(Convert.ToInt32(qRow["QuestionID"]));
                                                    rblQuetItem.ID = string.Format("RadioButton_{0}", qRow["QuestionID"]);
                                                    rblQuetItem.DataSource = dtQuestItem;
                                                    rblQuetItem.RepeatDirection = RepeatDirection.Vertical;
                                                    rblQuetItem.DataTextField = "QuestionItem";
                                                    rblQuetItem.DataValueField = "QuestionItemID";
                                                    rblQuetItem.DataBind();
                                                    if (itemAnswerID > 0)
                                                    {
                                                        rblQuetItem.Items.FindByValue(itemAnswerID.ToString()).Selected = true;
                                                    }
                                                    sectionPanel.Controls.Add(rblQuetItem);
                                                    sectionPanel.Controls.Add(new LiteralControl("<br>"));
                                                    break;

                                                case 4: //open ended question
                                                    System.Web.UI.HtmlControls.HtmlGenericControl newDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
                                                    newDiv.ID = string.Format("div_{0}", qRow["QuestionID"].ToString());
                                                    newDiv.Attributes.Add("style", "width:350px;float:left;");

                                                    Label lblQuestion = new Label();
                                                    lblQuestion.ID = string.Format("Label_{0}", qRow["QuestionID"].ToString());
                                                    lblQuestion.Text = qRow["Question"].ToString();

                                                    newDiv.Controls.Add(lblQuestion);
                                                    sectionPanel.Controls.Add(newDiv);

                                                    TextBox tbQuest = new TextBox();
                                                    tbQuest.ID = string.Format("TextBox_{0}", qRow["QuestionID"]);
                                                    tbQuest.Text = itemAnswer;
                                                    tbQuest.Style.Add("width", "500px");
                                                    tbQuest.Style.Add("float", "left");

                                                    sectionPanel.Controls.Add(tbQuest);
                                                    sectionPanel.Controls.Add(new LiteralControl("<br>"));
                                                    sectionPanel.Controls.Add(new LiteralControl("<br>"));
                                                    break;
                                            } //end switch
                                        }	 //end foreach

                                        //*****START: Adding comment textbox to each preclass section
                                        sectionPanel.Controls.Add(new LiteralControl("<br>"));
                                        sectionPanel.Controls.Add(new LiteralControl("<br>"));
                                        System.Web.UI.HtmlControls.HtmlGenericControl newDivs = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
                                        newDivs.Attributes.Add("style", "width:350px;float:left;");

                                        string Comment = Code.GetStudPreClassComment(PlanID, Convert.ToInt16(row["SectionID"]));
                                        Label lblComment = new Label();
                                        lblComment.Text = "Comment";
                                        newDivs.Controls.Add(lblComment);
                                        sectionPanel.Controls.Add(newDivs);
                                        TextBox tbcomment = new TextBox();
                                        tbcomment.ID = string.Format("tbSectionComment_{0}", row["SectionID"]);
                                        tbcomment.Text = Comment;
                                        tbcomment.Style.Add("width", "500px");
                                        tbcomment.Style.Add("float", "left");

                                        sectionPanel.Controls.Add(tbcomment);
                                        sectionPanel.Controls.Add(new LiteralControl("<br>"));
                                        sectionPanel.Controls.Add(new LiteralControl("<br>"));

                                        //*****END: Adding comment textbox to each preclass section
                                        PlaceHolder ph = new PlaceHolder();
                                        ph.Controls.Add(sectionPanel);

                                        PdfPTable table1 = new PdfPTable(3);
                                    }	//end if question 
                                }// end foreach
                            }

推荐答案


这篇关于我正在尝试将部分面板转换为pdf,我将其作为占位符中的参考传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 19:49