请帮忙。我有以下 - ListView及其两个处理程序AdminUsersListView_ItemEditing,AdminUsersListView_Load。
<asp:ListView ID="AdminUsersListView" runat="server"
onitemediting="AdminUsersListView_ItemEditing" onload="AdminUsersListView_Load"
DataKeyNames="UserId">
<LayoutTemplate>
<table cellpadding="2" runat="server" id="usersTable">
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><asp:LinkButton ID="EditButton" runat="server" Text="Edit" CommandName="Edit" /></td>
<td><asp:Label ID="NameLabel" runat="server" Text='<%# Eval("UserName") %>' /></td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr>
<td><asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" Text="Update" /><asp:LinkButton ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" /></td>
<td><asp:Label runat="server" ID="NameLabel" AssociatedControlID="NameTextBox" Text="Name"/><asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("UserName") %>' MaxLength="50" /></td>
</tr>
</EditItemTemplate>
</asp:ListView>
编译完成后,我会看到常用的页面,每个行都有表格和编辑按钮,我点击按钮,发回的内容正在发送但没有发生任何事情。
处理程序如下:
protected void AdminUsersListView_ItemEditing(Object sender, ListViewEditEventArgs e)
{
}
protected void AdminUsersListView_Load(Object sender, EventArgs e)
{
try
{
Int32 itemCount = Request["itemCount"] == null ? 10 : Int32.Parse(Request["itemCount"]);
Int32 itemPage = Request["itemPage"] == null ? 0 : Int32.Parse(Request["itemPage"]);
List<String> currentRoleList = Roles.GetRolesForUser().ToList();
UsersManager usersManager = new UsersManager();
IEnumerable<DbDataRecord> userList = usersManager.getAllowedUsersForRole(currentRoleList).ToList();
userList = userList.Skip(itemCount * itemPage).Take(itemCount);
AdminUsersListView.DataSource = userList;
AdminUsersListView.DataBind();
}
catch (Exception exceptionData)
{
Log.setMessage(exceptionData);
}
}
问题 - 为什么我总是看到ItemTemplate而看不到EditTemplate?
提前致谢,Art。
答案 0 :(得分:1)
您可以尝试使用load事件进行数据绑定吗?
答案 1 :(得分:1)
答案是直接设置编辑项目/行的索引,如下所示:
protected void lvwCustomers_ItemEditing(object sender, ListViewEditEventArgs e)
{
CloseInsert();
lvwCustomers.EditIndex = e.NewEditIndex;
BindList();
}