Specify an item placeholder by setting a control's ID property to "itemPlaceholder"
I have only 开发者_运维知识库single "Default.aspx" page and a single ListView Control. Why am I getting this error. Never Happened before
"An item placeholder must be specified on ListView 'ListView1'. Specify an item placeholder by setting a control's ID property to "itemPlaceholder". The item placeholder control must also specify runat="server"."
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TesterConcepts._Default"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
onselecting="ObjectDataSource1_Selecting" SelectMethod="GetItemsCollection"
TypeName="TesterConcepts.CutomDataSource">
<SelectParameters>
<asp:Parameter Name="items" Type="Object" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ListView ID="ListView1" runat="server" DataSourceID="ObjectDataSource1"
onselectedindexchanged="ListView1_SelectedIndexChanged">
</asp:ListView>
</body>
</html>
doing this was not helpful even
<asp:ListView ID="ListView1" runat="server" DataSourceID="ObjectDataSource1"
OnSelectedIndexChanged="ListView1_SelectedIndexChanged"
ItemPlaceholderID="PlaceHolder1">
</asp:ListView>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
Now it throws this exception
"An item placeholder must be specified on ListView 'ListView1'. Specify an item placeholder by setting a control's ID property to "PlaceHolder1". The item placeholder control must also specify runat="server""
In ListView, Layout Template is the template which decides the Layout of the data display . It should have an item placeholder tag with runat=”server” attribute.
Since the ListView's LayoutTemplate and ItemTemplate are each defined separately, we need some way to tell the LayoutTemplate, "Hey, for each record you are displaying, put the rendered item markup here." This is accomplished by adding a server-side control with the ID value specified by the ListView's ItemPlaceholderID property.
Ref - https://web.archive.org/web/20211020153238/https://www.4guysfromrolla.com/articles/122607-1.aspx
Hence U'll have to 1)Define a ItemsTemplate 2)Add a Placeholder in the LayoutTemplate
<tr runat="server" id="itemPlaceholder">
</tr>
or
<ItemTemplate>
<tr>
<td>
<asp:Label ID="MessageLabel" runat="server" Text='<%# Eval("Item") %>' />
</td>
<td>
<asp:Label ID="URLLabel" runat="server" Text='<%# Eval("URL") %>' />
</td>
</tr>
</ItemTemplate>
So the final Design will look like
<asp:ListView ID="NoticeItemsListView" runat="server">
<LayoutTemplate>
<table width="200px">
<tr>
<th>
Message
</th>
<th>
URL
</th>
</tr>
<tr runat="server" id="itemPlaceholder">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="MessageLabel" runat="server" Text='<%# Eval("Item") %>' />
</td>
<td>
<asp:Label ID="URLLabel" runat="server" Text='<%# Eval("URL") %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
Inside your ListView you've to add a LayoutTemplate containing the PlaceHolder:
<asp:ListView ID="listview1" runat="server" ItemPlaceholderID="PlaceHolder1" >
<LayoutTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server" />
</LayoutTemplate>
<ItemTemplate>
...
</ItemTemplate>
</asp:ListView>
Looks like you need to define the placeholder element structure for the item elements which the query will return.
I'd suggest reading this article. A little old, but illustrates the concept. https://web.archive.org/web/20211020153238/https://www.4guysfromrolla.com/articles/122607-1.aspx
精彩评论