Via CommandName="Delete" I am trying to delete a row from a ListView control, but not from a data source. On Pressing Delete I expect the web page to reload and show me an updated ListView (with deleting one row). But nothing changes, the ListView will display the same content after clicking Delete. What am I doing wrong?
<asp:ListView ID="ListView1" DataSourceID="XmlDataSource1" ItemContainerId="DataSection" runat="server"> <LayoutTemplate> <h3>Protocols to Upload...</h3> <table border=0 style="background-color:#9C9EFF; width: 100%;"> <tr align=left> <th>Region/Exam/Program</th><th>Protocol</th><th>Position</th> </tr> <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder> </table> </LayoutTemplate> <ItemTemplate> <tr> <td><%#XPath("Location/Path")%></td> <td><%#XPath("Location/Name")%></td> <td><%#XPath("Location/Position")%></td> <td style="width:40px"> <asp:LinkButton ID="SelectCategoryButton" runat="server" Text="Select" CommandName="Select"/> </td> </tr> </ItemTemplate> <SelectedItemTemplate> <tr id="Tr1" runat="server" style="background-color:#F7F3FF"> <td><%#XPath("Location/Path")%></td> <td><%#XPath("Location/Name")%></td> <td><%#XPath("Location/Position")%></td> <td style="width:40px"> <asp:LinkButton runat="server" ID="SelectCategoryButton" Text="Delete" CommandName="Delete" /> </td> </tr> </SelectedItemTemplate> <%-- <ItemSeparatorTemplate> <div style="height: 0px;border-top:dashed 1px #ff0000"></div> </ItemSeparatorTemplate>--%> </asp:ListView> <asp:XmlDataSource ID="XmlDataSource1" XPath="HttpRequestBO/ProtocolsDTO/ProtocolDTO" runat="server" DataFile="~/HttpRequestBo.Sample.xml"></asp:XmlDataSource>
And this is the 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); } }
If I do not use e.ExceptionHandled = true; , after clicking the "Delete" link on the web page, "The specified method is not supported." message. Why?
If I use the above line, the page refreshes, but I still see all the source lines (although when debugging, I see that the ListVieItem collection now contains only the less item.)
source share