Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>EDIT: Addressing two questions separately - one is that a control handle could not be grabbed, the other question is around deleting from a DataTable</p> <p><strong>Control Reference</strong></p> <p>If you're trying to get a handle on the control using this:</p> <pre><code>Dim txteno As Label = DirectCast(e.Item.FindControl("ID"), Label) </code></pre> <p>Then I think the control ID is incorrect as in your markup you've defined it as "lblId". So perhaps try:</p> <pre><code> Dim txteno As Label = DirectCast(e.Item.FindControl("lblId"), Label) </code></pre> <p>Also, I'm not sure what impact it would have but I would give the controls in the LayoutTemplate (so I am guessing the header for your ListView) different ID's to the controls in your ItemTemplate, if only for maintenance/cleanliness if nothing else.</p> <p>The label should also be bound like:</p> <pre><code>&lt;asp:Label id="lblId" runat="server" Text='&lt;%# Eval("ID") %&gt;'&gt;&lt;/asp:Label&gt; </code></pre> <p>So that in code-behind the text can be retrieved.</p> <p><strong>Deleting from DataTable</strong></p> <p>Based on the poster's comments, the DataTable's data is not coming from a database. </p> <p>Since you aren't connecting back to a database, you don't have to write SQL to remove items from the DataTable. </p> <p>It looks like you're storing the DataTable in session. And also that you are binding totally in code. As such, what you could do in your ItemCommand method is:</p> <ol> <li>Iterate over the data table to find the item to delete</li> <li>Delete the item (you could consult, for example, <a href="http://forums.asp.net/t/1300651.aspx" rel="nofollow noreferrer">this</a> forum post)</li> <li>Once the item has been removed from the DataTable, re-bind it to the list view. As an example of someone who seems to have been in a similar situation please see <a href="https://stackoverflow.com/questions/2723307/how-to-delete-a-item-in-a-asp-net-listview-and-persist-the-datasource">this</a></li> </ol> <p>HTH, Nathan</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