Enable 2-way databinding on nested listview
- by Lars Pedersen
I have a ASP.NET FormView, that - via an ObjectDataSource - is bound to my EventOrder-object:
[Serializable]
public class EventOrder
{
[Serializable]
public class OrderTicket
{
public int Qty { get; set; }
public int Id
{
get { return this.Ticket.Id; }
}
public Ticket Ticket { get; set; }
public double TicketPrice { get; set; }
}
[Serializable]
public class OrderExtra
{
public int Qty { get; set; }
public int Id
{
get { return this.Extra.Id; }
}
public Extra Extra { get; set; }
}
public Event Event { get; set; }
public List<OrderTicket> OrderTickets { get; set; }
public List<OrderExtra> OrderExtras { get; set; }
public UserProfile UserProfile { get; set; }
public List<Fee> Fees { get; set; }
public List<Discount> Discounts { get; set; }
public EventOrder()
{
this.OrderExtras = new List<OrderExtra>();
this.OrderTickets = new List<OrderTicket>();
this.Fees = new List<Fee>();
this.Discounts = new List<Discount>();
}
}
In my FormView, I have a bindingexpression on an inner listview for my collection of OrderTickets:
<asp:ListView Visible="false" runat="server" DataKeyNames="Id" ID="lvTickets" DataSource='<%# Bind("OrderTickets") %>'>
<ItemTemplate>
<asp:TextBox ID="TextBox5" Text='<%# Bind("Qty") %>' runat="server"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Ticket.Title") %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("TicketPrice") %>'></asp:Label><br />
</ItemTemplate>
My problem is that the Qty-property isn't databound to the object when the parent container is updated.
Is it possible to have this kind of parent-child relation with 2-way databinding? Can I force the child listview to update it's bound dataobject when I submit the form?