views:

928

answers:

3

Hi all,

I want to display the ListView InsertITemtemplate on button click (i.e. not to be displayed by default) but couldn't manage to do it. I have tried InsertItemPosition.None but then it does not display on button click as well. I am sure it must be a very simple thing but I am running out of time for this task. Any help would be greatly appreciated.

Ali

A: 

Add CommandName="Insert" to your ASP.NET button.

rick schott
A: 

_rick_schott are you sure there is ItemCommand property for a Button or a LinkButton? I could not find one.

Sorry, I edited my response.
rick schott
A: 

Try this:

    <asp:ListView ID="ListView1" runat="server" DataSourceID="LinqDataSource1" InsertItemPosition="None">
    <LayoutTemplate>
      <div runat="server" id="lstProducts">
        <asp:Button ID="btnAddProduct" runat="server" Text="Add Product" 
              CommandName="Create" OnClick="btnAddProduct_Click" />
        <div runat="server" id="itemPlaceholder" />
      </div>
    </LayoutTemplate>
    <ItemTemplate>
            <div><%# Eval("ProductName") %></div>
    </ItemTemplate>
    <InsertItemTemplate>
        <asp:TextBox ID="txtProductName" runat="server" ></asp:TextBox>
    </InsertItemTemplate>
</asp:ListView>

Then in code behind onclick event

    protected void btnAddProduct_Click(object sender, EventArgs e)
    {
        ListView1.InsertItemPosition = InsertItemPosition.FirstItem;
    }
Bharat
thanks Bharat. That worked ! (sorry for a late response)