EditTemplate for ListView not applicable

Please, help. I have the following: ListView and its two handlers 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>

After it is compiled, I see a regular page with a table and an “Edit” button for each line, I click on the button, it sends a message, but nothing happens.

The handlers are as follows:

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);
    }
}

Question: why do I always see ItemTemplate and not see EditTemplate?

Thanks in advance, Art.

+3
source share
2 answers

The answer is to directly set the edit index of the element / row as follows:

protected void lvwCustomers_ItemEditing(object sender, ListViewEditEventArgs e)
{
    CloseInsert();
    lvwCustomers.EditIndex = e.NewEditIndex;
    BindList();
}

: http://geekswithblogs.net/rashid/Default.aspx

+1

?

+1

Source: https://habr.com/ru/post/1779499/


All Articles