using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using TalentTestData.DAL; namespace TalentTest { public partial class Test1 : System.Web.UI.Page { private readonly string _connectionstring = ConfigurationManager.ConnectionStrings["Connect"].ConnectionString; protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { ReadQuestionsIntoTable(); } } private void ReadQuestionsIntoTable() { try { using (var context = new ExamDataDataContext(_connectionstring)) { var question = context.Questions.Select(x => x.Question1).ToList(); int rowCnt = question.Count; List<string> Choice_data = new List<string>(); var Choice = context.Questions.Select(X => new { X.Choice_1, X.Choice_2, X.Choice_3, X.Choice_4 }).ToList(); foreach (var item in Choice) { Choice_data.Add(item.Choice_1); Choice_data.Add(item.Choice_2); Choice_data.Add(item.Choice_3); Choice_data.Add(item.Choice_4); } int count = 0; int choice_count = 0; List<string> group_names = new List<string>(); for (int rowCtr = 1; rowCtr <= rowCnt; rowCtr++) { TableRow tr1 = new TableRow(); tab.Rows.Add(tr1); TableCell tc = new TableCell { Text = question[count] }; tr1.Cells.Add(tc); TableRow tr2 = new TableRow(); tab.Rows.Add(tr2); for (int j = 0; j < 4; j++) { // create a cell for the choice TableCell Cell = new TableCell { Width = 1000, // align the choices on the left HorizontalAlign = HorizontalAlign.Left }; tr2.Cells.Add(Cell); RadioButton rb = new RadioButton { // assign the radio button to Group + QuestionID GroupName = "Group" + rowCtr.ToString(), Text = Choice_data[choice_count], ID = "Radio", Visible = true }; Cell.Controls.Add(rb); choice_count++; } group_names.Add("Group" + rowCtr.ToString()); TableRow spacer = new TableRow { Height = 30 }; TableCell spacerCell = new TableCell { Height = 30 }; spacer.Cells.Add(spacerCell); tab.Rows.Add(spacer); count++; } } } catch(Exception e) { Console.WriteLine("Exception caught:", e); } } } }
rdbtnQuestionIDGroupName
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)