I REALLY DON'T KNOW WHAT APPROACH TO USE IN ORDER TO ACHIEVE THIS: I have searched everywhere for solutions to what I want to achieve but to no avail. It has been a difficult trying to dynamically create "Parent" repeater controls and "child" repeater controls. Where the "child" repeater control will be inside the parent" repeater control.
Basically I am trying to create a situation where Admin will create examination questions by clicking on "ADD Question" button to add these questions; each question will be saved and displayed in repeater control with options (answers) where students can choose and submit their answers. Each Question will be like the repeater header and inside each repeater control, there will be button where options will be added to the question (the option can also be removed).
The Question will be the "parent" repeater control, while the option will be the "child" repeater.
For example when Admin login. On the webpage the admin will type the question in a textbox and click "ADD QUESTION" button and the question will be added to the database and display inside a control with another button to add options (i.e. answers); the options will also be saved and displayed for students to choose from. Each option will come with a radiobutton so that students who are sitting for the examination can select an option by clicking on any radio button for each question.
Here is a screenshot of two questions with two options each, where users can choose and submit
I tried to dynamically create repeater control for this but I don't know if it is the right approach for this kind of goal.
SqlCommand cmd = new SqlCommand();
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
Repeater Repeater1 = new Repeater();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Repeater1.DataSource = ds;
Repeater1.DataBind();
foreach (RepeaterItem repeatItem in Repeater1.Items)
{
if (repeatItem.ItemIndex == 0)
{
RepeaterItem headerItem = new RepeaterItem(repeatItem.ItemIndex, ListItemType.Header);
HtmlGenericControl hTag = new HtmlGenericControl("h4");
hTag.InnerHtml = "Employee Name";
repeatItem.Controls.Add(hTag);
}
RepeaterItem repeaterItem = new RepeaterItem(repeatItem.ItemIndex, ListItemType.Item);
Label lbl = new Label();
lbl.Text = string.Format("{0} {1} <br />", ds.Tables[0].Rows[repeaterItem.ItemIndex]
["FirtsName"], ds.Tables[0].Rows[repeaterItem.ItemIndex]["LastName"]);
repeaterItem.Controls.Add(lbl);
repeaterItem = new RepeaterItem(repeaterItem.ItemIndex, ListItemType.Separator);
LiteralControl ltrlHR = new LiteralControl();
ltrlHR.Text = "<hr />";
repeaterItem.Controls.Add(ltrlHR);
}
Panel1.Controls.Add(Repeater1);
I really need your help to achieve this, please.