Click here to Skip to main content
15,886,541 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello I have a session variable "question" whose fields are of type string ques , string qtype, list<string> correctans, list<string> yourans.
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<string> type field.
this is how i m implementing.

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

aspx page
HTML
<DataList ID="DataList1" runat="server" Width="100%"&gt;
    &lt;HeaderTemplate&gt;
        <a href="showresult.aspx">Show Result</a>
        <h2>Review Questions</h2>
        <hr size="5" style="color: red" />
    &lt;/HeaderTemplate&gt;

    <itemtemplate>
        <pre style="color: Red; background-color: #eeeeee">&lt;%# DataBinder.Eval( Container.DataItem,"QuestionText")%&gt;</pre>
        <pre>1.&lt;%# DataBinder.Eval( Container.DataItem,"Answer1") %&gt;</pre>
        <pre>2.&lt;%# DataBinder.Eval( Container.DataItem,"Answer2") %&gt;</pre>
        <pre>3.&lt;%# DataBinder.Eval( Container.DataItem,"Answer3") %&gt;</pre>
        <pre>4.&lt;%# DataBinder.Eval( Container.DataItem,"Answer4") %&gt;</pre>

    </itemtemplate>
    <itemtemplate>
        <pre>Correct Answer :</pre>
        &lt;asp:Repeater ID="Repeater1" runat="server" &gt;

            <itemtemplate>
                <span>&lt;%# DataBinder.Eval( Container.DataItem,"cans") %&gt;</span>
            </itemtemplate>

</itemtemplate>
    <separatortemplate>
        <hr size="2" style="color: Red" />
    </separatortemplate>

    <footertemplate>
        <hr size="5" style="color: red" />
        <a href="showresult.aspx">Show Result</a>
    </footertemplate>


What I have tried:

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>
Show Result

Review Questions




</HeaderTemplate>

<itemtemplate>
<%# DataBinder.Eval( Container.DataItem,"QuestionText")%>

1.<%# DataBinder.Eval( Container.DataItem,"Answer1") %>

2.<%# DataBinder.Eval( Container.DataItem,"Answer2") %>

3.<%# DataBinder.Eval( Container.DataItem,"Answer3") %>

4.<%# DataBinder.Eval( Container.DataItem,"Answer4") %>



<itemtemplate>
Correct Answer :

<asp:Repeater ID="Repeater1" runat="server" >

<itemtemplate>
<%# DataBinder.Eval( Container.DataItem,"cans") %>







<separatortemplate>




<footertemplate>


Show Result

Posted
v3
Comments
[no name] 5-Feb-16 4:05am    
So what is the error you are getting - provide it details.

Secondly please format your question properly because your code snippet is rendering as HTML.
Member 11360268 5-Feb-16 4:10am    
error is question is not visible only correctanswer label is displaying.
Why are you binding two lists to one DataList?

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