Fábio Silva
Fábio Silva

Reputation: 139

ASP.NET InsertItemTemplate always visible

I have a ListView. At the moment I have to click in a Button to show the InsertItemTemplate, as shown below.

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;
}

How can I have the InsertItemTemplace visible without needing to click a button?

Upvotes: 0

Views: 710

Answers (1)

F&#225;bio Silva
F&#225;bio Silva

Reputation: 139

Just add that line in the ListView declaration:
InsertItemPosition="LastItem" to show, the template, at the end or
InsertItemPosition="FirstItem" to show, the template, in the top
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>

Upvotes: 1

Related Questions