Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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
                            }
Posted
Updated 5-Dec-13 10:04am
v2

1 solution

for help with creating PDF programmatically, use the itextSharp Library, used it and it works great!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900