我目前正在開發留言系統,我需要管理員刪除特定的日誌。問題是我試圖刪除它時出現錯誤。c#Datalist刪除特定行。
的錯誤是:Index was outside the range. It may not be negative and must be less than the crowd size. Parameter name: index
我的代碼:asp.net
<asp:DataList ID="guestBookDataList" runat="server" ondeletecommand="guestBookDataList_DeleteCommand">
<ItemTemplate>
<div id="guest-books">
<span class="guestBook-Id"> # <%#DataBinder.Eval(Container.DataItem, "id") %></span><span class="guestBook-Name">Name: <%#DataBinder.Eval(Container.DataItem, "Name") %> </span>
<span class="guestBook-Date"> Date: <%#DataBinder.Eval(Container.DataItem, "Date") %> </span> <br />
<span class="guestBook-Text"> <%#DataBinder.Eval(Container.DataItem, "text") %> </span>
<asp:LinkButton ID="LinkButtonDelete" CssClass="gastbok-remove" runat="server" CommandName="Delete">Delete<%#DataBinder.Eval(Container.DataItem, "id") %></asp:LinkButton>
</div>
</ItemTemplate>
</asp:DataList>
我的LinkButton是在數據列表的每個項目的刪除按鈕。
,這就是給我的錯誤我的C#代碼:
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();
}
Basiclly我只是需要從DATABSE retrive的guestbooklogs ID,所以我可以將其刪除。
一直在嘗試很多不同的方法,並使用谷歌搜索這個,但我不能得到它的工作。所以現在我在問你。謝謝你的時間。
AHH太感謝你了。你救了我的一天:)。它工作完美 – dumbel 2012-02-14 23:33:33
你能接受答案嗎? – 2012-02-15 17:45:05