开发者

EditTemplate for ListView doesn't apply

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("User开发者_开发百科Name") %>' MaxLength="50" /></td>
          </tr>
        </EditItemTemplate>
    </asp:ListView>

After it is compiled i see usual page with table and Edit button against each row, i click on the button, post back is sending but nothing is happening.

Handlers are the following:

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 i always see ItemTemplate and cannot see EditTemplate?

Thanks in advance, Art.


Can you try data binding outwith the load event?


Answer is to directly set index of editing item / row like this :

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

Detailed description can be found here : http://geekswithblogs.net/rashid/Default.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜