gpt4 book ai didi

c# - Listview Itemediting 不工作

转载 作者:行者123 更新时间:2023-11-28 01:47:00 25 4
gpt4 key购买 nike

我不知道为什么会出现此错误,但我认为我的代码是正确的。

HTML

<asp:ListView ID="lvwData" runat="server" OnItemCommand="Student_OnItemCommand" EnableViewState="true"
DataKeyNames="id">
<LayoutTemplate>
<table class="table-list table-list-gridded" id="dataTable" border="0" cellspacing="0"
cellpadding="5">
<thead>
<th class="id">
ROW #
</th>
<th>
Student ID
</th>
<th>
First Name
</th>
<th>
Last Name
</th>
<th>
Course
</th>
<th class="action">
<span>ACTIONS</span>
</th>
</thead>
<tbody id="itemPlaceholder" runat="server">
</tbody>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td align="center" class="id">
<%# Container.DataItemIndex + 1 %>
</td>
<td>
<asp:Label ID="lblStudentID" runat="server" Text='<%# Eval("student_id") %>' />
</td>
<td>
<asp:Label ID="lblFirstName" runat="server" Text='<%# Eval("firstname") %>' />
</td>
<td>
<asp:Label ID="lblLastName" runat="server" Text='<%# Eval("lastname") %>' />
</td>
<td>
<asp:Label ID="lblCourse" runat="server" Text='<%# Eval("course") %>' />
</td>
<td align="center" class="action">
<asp:LinkButton ID="lnkEdit" class="btn btn-small" Text="Edit" CommandName="Edit"
CommandArgument='<%# Eval("ID") %>' runat="server"><i class="icon-pencil"></i></asp:LinkButton>
<asp:LinkButton ID="DeleteLinkButton" Text="Delete" CommandName="Delete" CommandArgument='<%# Eval("ID") %>'
OnClientClick="return confirm('Are you sure you want to delete this Employee?');"
runat="server" class="btn btn-small"><i class="icon-remove"></i></asp:LinkButton>
</td>
</ItemTemplate>
<EmptyDataTemplate>
<div class="centered alert alert-error">
No list of records to display.
</div>
</EmptyDataTemplate>
</asp:ListView>

背后的 C# 代码:

protected void Student_OnItemCommand(object sender, ListViewCommandEventArgs e)
{
switch (e.CommandName)
{
case "Delete":
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
string employeeID = lvwData.DataKeys[dataItem.DisplayIndex].Value.ToString();

DBConnect db = new DBConnect();
db.Delete("delete from students where id = '" + employeeID + "'");
Response.Redirect("~/Users/Student.aspx");
break;
case "Edit":
mvStudents.ActiveViewIndex = 1;
break;
}
//if (String.Equals(e.CommandName, "Delete"))
//{

//}
//else if (string.Equals(e.CommandName, "Edit"))
//{
// ListViewDataItem dataItem = (ListViewDataItem)e.Item;
// string employeeID = lvwData.DataKeys[dataItem.DisplayIndex].Value.ToString();


//}
}

堆栈跟踪:

[InvalidOperationException: The ListView 'lvwData' raised event ItemEditing which wasn't handled.] System.Web.UI.WebControls.ListView.OnItemEditing(ListViewEditEventArgs e) +305573 System.Web.UI.WebControls.ListView.HandleEdit(Int32 itemIndex) +51 System.Web.UI.WebControls.ListView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +324 System.Web.UI.WebControls.ListView.OnBubbleEvent(Object source, EventArgs e) +227 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.ListViewDataItem.OnBubbleEvent(Object source, EventArgs e) +112 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121 System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +156 System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9528578 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

最佳答案

我会建议你改变你的命令名称原因:- 单击按钮的 CommandName 是“编辑”,然后它会将 ListView 置于编辑模式,尝试将 CommandName =“Edit”修改为“modify”之类的东西......这很容易

希望你明白。

关于c# - Listview Itemediting 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22137354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com