c# Datalist delete specific row.
<p>I'm currently developing a guestbook system, and I need admins to remove specific logs. The problem is I'm getting an error when trying to delete it.</p>

<p>The error is: <code>Index was outside the range. It may not be negative and must be less than the crowd size.
Parameter name: index</code></p>

<p>My code: asp.net</p>

<pre><code> &lt;asp:DataList ID="guestBookDataList" runat="server" ondeletecommand="guestBookDataList_DeleteCommand"&gt;
    &lt;ItemTemplate&gt;
        &lt;div id="guest-books"&gt;
            &lt;span class="guestBook-Id"&gt; # &lt;%#DataBinder.Eval(Container.DataItem, "id") %&gt;&lt;/span&gt;&lt;span class="guestBook-Name"&gt;Name: &lt;%#DataBinder.Eval(Container.DataItem, "Name") %&gt; &lt;/span&gt;
            &lt;span class="guestBook-Date"&gt; Date: &lt;%#DataBinder.Eval(Container.DataItem, "Date") %&gt; &lt;/span&gt; &lt;br /&gt;
            &lt;span class="guestBook-Text"&gt; &lt;%#DataBinder.Eval(Container.DataItem, "text") %&gt; &lt;/span&gt;
           &lt;asp:LinkButton ID="LinkButtonDelete" CssClass="gastbok-remove" runat="server" CommandName="Delete"&gt;Delete&lt;%#DataBinder.Eval(Container.DataItem, "id") %&gt;&lt;/asp:LinkButton&gt;
        &lt;/div&gt;                
    &lt;/ItemTemplate&gt;
&lt;/asp:DataList&gt;
</code></pre>

<p>My linkbutton is the delete button for each item in the datalist. </p>

<p>And my C# code that's giving me the error:</p>

<pre><code>protected void guestBookDataList_DeleteCommand(
    object source, DataListCommandEventArgs e)
{
    int id = Convert.ToInt32(guestBookDataList.DataKeys[e.Item.ItemIndex]);
    db.deleteGeustBookLog(id); //calls the sql command
    bindList();
}
</code></pre>

<p>Basiclly I just need to retrive the guestbooklogs ID from the databse so I can delete it.</p>

<p>Been trying a lot of different methods and googling about this but I can't get it to work. So now I'm asking you. Thanks for your time. </p>
