2

I want to bind listview inside the listview. I have an object which contains another object list object inside it.

Here I have result object and I have another weeklyresult(List) object in it. I am trying to bind outer list with the result object.

Here is the cs code:

Populate data in resultListobject :

                ResultListView.DataSource = resultList;
                ResultListView.DataBind();
                Response.Write(resultList);

Classes Result and weeklyresult :

class Result {
    public string examDate { get; set; }
    public List<WeeklyResult> weeklyResultList = null;
}

class WeeklyResult {
    public string subject { get; set; }
    public double marksObtained { get; set; }
    public double outOff { get; set; }
}

Now here is my asp.net code:

<asp:ListView ID="ResultListView" runat="server">
            <ItemTemplate>
            <asp:Label runat="server"></asp:Label>

            <table id="Table1" runat="server">
            <tr>
            <td>Date :<%#Eval("examDate")%> </td>
            <td>Marks Obtained</td>
            <td>Out off</td>
            </tr> </table>

                <asp:ListView ID="InnerListView" runat="server">
                <ItemTemplate>
                <asp:Label ID="Label0"  runat="server" Text="abc<%#Eval('weeklyResultList.subject')%>"></asp:Label>
                <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
                <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
                <asp:Label ID="Label3" runat="server" Text=""></asp:Label>
                </ItemTemplate>
                </asp:ListView>

            </ItemTemplate>
   </asp:ListView>

The data in the outer list is coming but nothing is getting displayed in the inner list. Can you please suggest what I am doing wrong.

Thanks, Amandeep

3 Answers 3

1

Had to use:

DataSource='<%#Eval("weeklyResultList")
Sign up to request clarification or add additional context in comments.

Comments

0

Try to bind inner ListView in first listView's ItemDataBount Event. Simply assign other DataSource. It will simply solve your problem...

Comments

0

The question is old, but I believe it may help some people. Try this:

Datasource will be the name of the List inside the object

Change:

<asp:ListView ID="InnerListView" runat="server">

To:

<asp:ListView ID="InnerListView" runat="server" DataSource='<%#Eval("weeklyResultList")%>'>

And to access the attributes of each object in the list.

Change:

<asp:Label ID="Label0"  runat="server" Text="abc<%#Eval('weeklyResultList.subject')%>"></asp:Label>

To:

<asp:Label ID="Label0"  runat="server" Text="abc<%#Eval('subject')%>"></asp:Label>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.