2
Answers

to Display list<string> in repeator inside data list control

monica singh

monica singh

8y
428
1
hello I have a session variable "question" whose fields are of type string ques , string qtype, list correctans, listyourans.
now i have to display the question with all values,
i have pased question through session variable , in datalist control, but since two fields are of list , it is giving error,
can you plz guide how should i display a question in datalist with list type field.
 

C# Code
exam = (Examination)Session["questions"];
Examination exam = (Examination)Session["Question"];
DataList1.DataSource = exam.questions;
DataList1.DataSource = exam.questions;
DataList1.DataBind();
 

aspx page
 
<asp:DataList ID="DataList1" runat="server" Width="100%">
<HeaderTemplate>
<a href="showresult.aspx">Show Result</a>
<h2>Review Questions</h2>
<hr size="5" style="color: red" />
</HeaderTemplate>
<ItemTemplate>
<pre style="color: Red; background-color: #eeeeee"><%# DataBinder.Eval( Container.DataItem,"QuestionText")%></pre>
<pre>1.<%# DataBinder.Eval( Container.DataItem,"Answer1") %></pre>
<pre>2.<%# DataBinder.Eval( Container.DataItem,"Answer2") %></pre>
<pre>3.<%# DataBinder.Eval( Container.DataItem,"Answer3") %></pre>
<pre>4.<%# DataBinder.Eval( Container.DataItem,"Answer4") %></pre>
</ItemTemplate>
<ItemTemplate>
<pre>Correct Answer :</pre>
<asp:Repeater ID="Repeater1" runat="server" >
<ItemTemplate>
<span><%# DataBinder.Eval( Container.DataItem,"cans") %></span>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
<SeparatorTemplate>
<hr size="2" style="color: Red" />
</SeparatorTemplate>
<FooterTemplate>
<hr size="5" style="color: red" />
<a href="showresult.aspx">Show Result</a>
</FooterTemplate>
</asp:DataList>
Answers (2)