0

OnItemCommand当我按下里面的按钮时,事件不会触发?我尝试了一些东西,但什么也没发生。我忘了放什么东西吗?我应该怎么做才能修复它?clickItemTemplate

页面:

<asp:ListView ID="ShowPostsListView" runat="server" OnItemDataBound="ShowPostsListView_ItemDataBound" OnItemCommand="ShowPostsListView_ItemCommand">
    <ItemTemplate>
      <asp:Button ID="AddCommentButton" CssClass="addCommentButton" runat="server" Text="Add Comment" CommandName="Add Comment" />
    </ItemTemplate>
</asp:ListView>

页面后面的代码:

protected void ShowPostsListView_ItemCommand(object sender, ListViewCommandEventArgs e)
{
    if (e.CommandName == "Add Comment")
    {
                 ...
    }
}
4

2 回答 2

0

做同样事情的另一种方法是将 OnClick 事件处理程序添加到按钮,如下所示:

<asp:ListView ID="ShowPostsListView" runat="server"    
 OnItemDataBound="ShowPostsListView_ItemDataBound">
    <ItemTemplate>
      <asp:Button ID="AddCommentButton" CssClass="addCommentButton" 
        OnClick="addCommentButton_OnClick" runat="server" 
        Text="Add Comment"  />
    </ItemTemplate>
</asp:ListView>

接着:

protected void addCommentButton_OnClick(obejct sender, EventArgs e)
{

}
于 2013-03-23T13:40:05.410 回答
0

have you set the eventhandling in webconfig false to get rid of the error, if you did that please change it back to same way or make it true, and before binding the data to your listview jst add

if(!isPostBack)
ListView1.Databind();

i hope this will solve the problem, and your event will fire

于 2013-03-24T11:44:54.140 回答