ListView won't display InsertItemTemplate

thanhp

New Member
I have a \[code\]ListView\[/code\] inside of an \[code\]AccordionPane\[/code\] with an "Add Record" button. When I click the "Add Record" button, the \[code\]InsertItemTemplate\[/code\] does not appear. Strangely, if I click the button a second time, it does appear. I've tried a number of things like adding \[code\]CommandName="InitInsert"\[/code\] or \[code\]CommandName="Insert"\[/code\] to the button, taking the \[code\]ListView\[/code\] out of the \[code\]Accordion\[/code\] that it's inside of, taking the "Insert" button out of the \[code\]ListView\[/code\] then out of the \[code\]Accordion\[/code\], all to no avail. Is there something obvious that I'm missing? What am I doing wrong?\[code\]<asp:ListView runat="server" ID="List1" OnItemDataBound="List1_ItemDataBound" OnItemCommand="List1_ItemCommand" OnItemEditing="List1_ItemEditing" OnItemUpdating="List1_ItemUpdating" OnItemCanceling="List1_ItemCancelling" OnItemDeleting="List1_ItemDeleting" OnItemInserting="List1_ItemInserting" OnSorting="List1_Sorting"><LayoutTemplate> <table border="0" cellpadding="1" cellspacing="0"> <thead> <tr> <th><asp:LinkButton runat="server" ID="BtnCmpnyId" CommandName="Sort" CommandArgument="CmpnyId" Text="Company Code" /></th> ... more columns ... </tr> </thead> <tbody> <tr runat="server" id="itemPlaceholder"></tr> </tbody> <tfoot> <tr><td colspan="7" style="text-align: center;"> <asp:Button runat="server" ID="BtnAddRecord" Text="Add Record" OnClick="BtnAddRecord_Click" /> </td></tr> </tfoot> </table></LayoutTemplate><InsertItemTemplate> <tr> <td> <asp:HiddenField runat="server" ID="HiddenID" Value="http://stackoverflow.com/questions/12750843/-1" /> <asp:TextBox runat="server" ID="TextCmpnyId" Text='<%# Eval("CmpnyId") %>' MaxLength="6" Width="50" /> </td> ... more fields ... </tr></InsertItemTemplate>... other templates ...</asp:ListView>\[/code\]In my code behind:\[code\]protected void BtnAddRecord_Click(object sender, EventArgs e){ List1.EditIndex = -1; List1.InsertItemPosition = InsertItemPosition.LastItem; //Button button = (Button)List1.Controls[0].FindControl("BtnAddRecord"); //button.Visible = false;}\[/code\]
 
Back
Top