bind parent child listview asp.net
- by Chris
I'm trying to display two linq query results in a prent and child listview.
I have the following code which gets the correct values to populate the listviews but when I nest the child listview inside the parent list view, I get an error saying "The name 'ListView2' does not exist in the current context".
I presume I need to bind the two listviews in the code behind but my problem is I don't know how or the best way to do this. I have read a couple of posts on similar problems but my lack of knowledge on the subject doesn't make it clear to me.
Please can somebody help me figure this out? It's the final piece of code I need to complete.
Many thanks in advance.
Here is my .aspx code:
<asp:ListView ID="ListView1" runat="server">
<EmptyDataTemplate>No data was returned.</EmptyDataTemplate>
<ItemSeparatorTemplate><br /></ItemSeparatorTemplate>
<ItemTemplate>
<li>
<asp:Label ID="LabelID" runat="server" Text='<%# Eval("RecordID") %>'></asp:Label><br />
<asp:Label ID="LabelNumber" runat="server" Text='<%# Eval("CartID") %>'></asp:Label><br />
<asp:Label ID="LabelName" runat="server" Text='<%# Eval("Number") %>'></asp:Label><br />
<asp:Label ID="LabelDestination" runat="server" Text='<%# Eval("Destination") %>'></asp:Label><br />
<asp:Label ID="LabelPkgName" runat="server" Text='<%# Eval("PkgName") %>'></asp:Label>
<li>
<!-- LIST VIEW FOR FEATURES -->
<asp:ListView ID="ListView2" runat="server">
<EmptyDataTemplate>No data was returned.</EmptyDataTemplate>
<ItemSeparatorTemplate><br /></ItemSeparatorTemplate>
<ItemTemplate>
<li>
<asp:Label ID="LabelFeatureName" runat="server" Text='<%# Eval("FeatureName") %>'></asp:Label><br />
<asp:Label ID="LabelFeatureSetUp" runat="server" Text='<%# Eval("FeatureSetUp") %>'></asp:Label><br />
<asp:Label ID="LabelFeatureMonthly" runat="server" Text='<%# Eval("FeatureMonthly") %>'></asp:Label><br />
</li>
</ItemTemplate>
<LayoutTemplate>
<ul ID="itemPlaceholderContainer" runat="server" style="">
<li runat="server" id="itemPlaceholder" />
</ul>
</LayoutTemplate>
</asp:ListView>
<!-- LIST VIEW FOR FEATURES [END] -->
</li>
</li>
</ItemTemplate>
<LayoutTemplate>
<ul ID="itemPlaceholderContainer" runat="server" style="">
<li runat="server" id="itemPlaceholder" />
</ul>
</LayoutTemplate>
</asp:ListView>
Here is my code behind:
MyShoppingCart userShoppingCart = new MyShoppingCart();
string cartID = userShoppingCart.GetShoppingCartId();
using (ShoppingCartv2Entities db = new ShoppingCartv2Entities())
{
var CartNumber = from c in db.NewViews
where c.CartID == cartID
select c;
foreach (NewView item in CartNumber)
{
ListView1.DataSource = CartNumber;
ListView1.DataBind();
}
var CartFeature = from f in db.NewViews
join o in db.NumberFeatureViews on f.RecordID equals o.RecordID
where f.CartID == cartID
select new { o.FeatureName, o.FeatureSetUp, o.FeatureMonthly };
foreach (var x in CartFeature)
{
ListView2.DataSource = CartFeature;
ListView2.DataBind();
}
}