FormView/ListView master/detail problem

H

Henri Fournier

I'm using a LinqDataSource with a FormView to display a single master
record. In the FormView's ItemTemplate, I have a nested ListView to insert,
edit, delete the Details record. However, The ListView doesn't display
anything, so I can't add records. I can't figure out what I'm missing to
make this work.

Henri

Note: I removed all the extra data fields for simplicity.

<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="MyDataContext" EnableDelete="True"
EnableInsert="True" EnableUpdate="True"
oninserted="LinqDataSource1_Inserted"
oninserting="LinqDataSource1_Inserting"
onselecting="LinqDataSource1_Selecting"
TableName="Company" Where="ItemID == @ItemID">

<WhereParameters>
<asp:parameter Name="ItemID" Type="Int32" />
</WhereParameters>

</asp:LinqDataSource><asp:FormView ID="FormView1" runat="server"
DataKeyNames="ItemID" DataSourceID="LinqDataSource1">
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>Name:</td>
<td><asp:Label ID="NameLabel" runat="server" Text='<%#
Eval("Name") %>' /></td>
</tr>
</table>
<asp:panel ID="pnlContacts" runat="server" Visible="True">
<hr />
<h2>Contacts</h2>
<asp:ListView ID="lvContacts" runat="server" DataSource='<%#
Eval("Contacts") %>'>
<LayoutTemplate>
<div>
<table id="itemPlaceholderContainer" border="0"
cellpadding="0" cellspacing="0">
<tr id="itemPlaceholder" runat="server" />
</table>
</div>
</LayoutTemplate>
<ItemTemplate>
<tr id="tr1" runat="server">
<td rowspan="5"><asp:Button ID="btnEdit"
runat="server" CommandName="Edit" Text="Edit" /></td>
<td>Name: <asp:Label ID="lblFirstName"
runat="server" Text='<%# Eval("FirstName") %>' />&nbsp;
<asp:Label ID="lblLastName" runat="server"
Text='<%# Eval("LastName") %>' /></td>
</tr>
</ItemTemplate>
<InsertItemTemplate>
<tr id="tr1" runat="server">
<td rowspan="5"><asp:Button ID="btnInsert"
runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="btnCancel" runat="server"
CommandName="Cancel" Text="Cancel" /></td>
<td>Name: <asp:TextBox ID="txtFirstName"
runat="server" Text='<%# Bind("FirstName") %>' />&nbsp;
<asp:TextBox ID="txtLastName" runat="server"
Text='<%# Bind("LastName") %>' /></td>
</tr>
</InsertItemTemplate>
<EditItemTemplate>
<tr id="tr1" runat="server">
<td rowspan="5"><asp:Button ID="btnUpdate"
runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="btnCancel" runat="server"
CommandName="Cancel" Text="Cancel" /></td>
<td>Name: <asp:TextBox ID="txtFirstName"
runat="server" Text='<%# Bind("FirstName") %>' />&nbsp;
<asp:TextBox ID="txtLastName" runat="server"
Text='<%# Bind("LastName") %>' /></td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<tr id="trNoData" runat="server">
<td colspan="3">No Team Members yet.</td>
</tr>
</EmptyDataTemplate>
</asp:ListView>
</asp:panel>
</ItemTemplate>
</asp:FormView>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,818
Messages
2,569,727
Members
45,664
Latest member
Phil79581

Latest Threads

Top