ASP.NET InsertItemTemplate始终可见

时间:2015-02-12 23:15:23

标签: c# asp.net listview webforms

我有一个ListView。目前,我必须点击按钮才能显示InsertItemTemplate,如下所示。

Default.aspx

<LayoutTemplate>
    <ul>
        <asp:PlaceHolder ID="ItemPlaceHolder" runat="server" />
    </ul>
    <asp:Button ID="New" Text='New' CommandName="Create" OnClick="Novo_Click" runat="server" />
</LayoutTemplate>

Default.aspx.cs

protected void Novo_Click(object sender, EventArgs e)
{
    ListViewID.InsertItemPosition = InsertItemPosition.LastItem;
}

如何在不需要点击按钮的情况下显示InsertItemTemplace

1 个答案:

答案 0 :(得分:1)

只需在ListView声明中添加该行: InsertItemPosition =“LastItem”以显示模板,最后或
InsertItemPosition =“FirstItem”在顶部显示模板
The default is InsertItemPosition.None, which indicates that the InsertItemTemplate content will not be rendered by the ListView control.

<asp:ListView ID="ContactsListView" 
  DataSourceID="ContactsDataSource" 
  DataKeyNames="ContactID"
  OnItemInserted="ContactsListView_ItemInserted"  
  InsertItemPosition="LastItem"
  runat="server">
    ...
</asp:ListView>