Note that there are some explanatory texts on larger screens.

plurals
  1. POAsp.Net ListView how to delete a row without deleting from datasource
    text
    copied!<p>Through <code>CommandName="Delete"</code> I try to delete a line from the ListView control but not from the datasource. On Pressing Delete I expect the webpage to reload and show me the updated ListView(with one line deleted). But nothing changes, the ListView will display the same content after pressing Delete. What do I do wrong?</p> <pre><code> &lt;asp:ListView ID="ListView1" DataSourceID="XmlDataSource1" ItemContainerId="DataSection" runat="server"&gt; &lt;LayoutTemplate&gt; &lt;h3&gt;Protocols to Upload...&lt;/h3&gt; &lt;table border=0 style="background-color:#9C9EFF; width: 100%;"&gt; &lt;tr align=left&gt; &lt;th&gt;Region/Exam/Program&lt;/th&gt;&lt;th&gt;Protocol&lt;/th&gt;&lt;th&gt;Position&lt;/th&gt; &lt;/tr&gt; &lt;asp:PlaceHolder ID="itemPlaceholder" runat="server"&gt;&lt;/asp:PlaceHolder&gt; &lt;/table&gt; &lt;/LayoutTemplate&gt; &lt;ItemTemplate&gt; &lt;tr&gt; &lt;td&gt;&lt;%#XPath("Location/Path")%&gt;&lt;/td&gt; &lt;td&gt;&lt;%#XPath("Location/Name")%&gt;&lt;/td&gt; &lt;td&gt;&lt;%#XPath("Location/Position")%&gt;&lt;/td&gt; &lt;td style="width:40px"&gt; &lt;asp:LinkButton ID="SelectCategoryButton" runat="server" Text="Select" CommandName="Select"/&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/ItemTemplate&gt; &lt;SelectedItemTemplate&gt; &lt;tr id="Tr1" runat="server" style="background-color:#F7F3FF"&gt; &lt;td&gt;&lt;%#XPath("Location/Path")%&gt;&lt;/td&gt; &lt;td&gt;&lt;%#XPath("Location/Name")%&gt;&lt;/td&gt; &lt;td&gt;&lt;%#XPath("Location/Position")%&gt;&lt;/td&gt; &lt;td style="width:40px"&gt; &lt;asp:LinkButton runat="server" ID="SelectCategoryButton" Text="Delete" CommandName="Delete" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/SelectedItemTemplate&gt; &lt;%-- &lt;ItemSeparatorTemplate&gt; &lt;div style="height: 0px;border-top:dashed 1px #ff0000"&gt;&lt;/div&gt; &lt;/ItemSeparatorTemplate&gt;--%&gt; &lt;/asp:ListView&gt; &lt;asp:XmlDataSource ID="XmlDataSource1" XPath="HttpRequestBO/ProtocolsDTO/ProtocolDTO" runat="server" DataFile="~/HttpRequestBo.Sample.xml"&gt;&lt;/asp:XmlDataSource&gt; </code></pre> <p>And this is the code behind:</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { } protected void ListView1_OnItemDeleted(Object sender, ListViewDeletedEventArgs e) { if (e.Exception != null) { e.ExceptionHandled = true; } } protected void ListView1_OnItemCommand(object sender, ListViewCommandEventArgs e) { if (String.Equals(e.CommandName, "Delete")) { ListViewDataItem dataItem = (ListViewDataItem)e.Item; ListView1.Items.Remove(dataItem); } } </code></pre> <p>If I don't use the <code>e.ExceptionHandled = true;</code>, after pressing the Delete link the web page will come up with a "Specified method is not supported." message. Why?</p> <p>If I use the above mentioned line, then the page refreshes but I can still see all original lines (although on debugging I can see that the ListVieItem collection now only contains an item less.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload