嵌套列表视图的itemdatabound事件

时间:2012-03-17 19:10:08

标签: asp.net listview nested itemdatabound

我有一个嵌套的listview,我在父'ItemDataBound'事件上进行了数据绑定,但是我如何访问/注册嵌套的listview的itemdatabound事件?

谢谢!

编辑

我的父列表视图itemdatabound现在看起来像这样,

Protected Sub lvwManagePolicy_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles lvwManagePolicy.ItemDataBound

    If e.Item.ItemType = ListViewItemType.DataItem Then
        Dim rv As DataRowView = CType(e.Item.DataItem, DataRowView)

        Me.dsAccoutnTransactionHistory = Wrap.getWrapAccountTransactionHistory(rv!PLATFORM_ID, False)
        Dim lvwTransactionHistory As ListView = DirectCast(e.Item.FindControl("lvwTransactionHistory"), ListView)
        lvwTransactionHistory.ItemDataBound += New EventHandler(Of ListViewItemEventArgs)(lvwTransactionHistory_ItemDataBound)
        lvwTransactionHistory.DataSource = dsAccoutnTransactionHistory
        lvwTransactionHistory.DataBind()
    End If

End Sub

但我收到错误

  

BC32022:'公共事件ItemDataBound(发件人为对象,e As   System.Web.UI.WebControls.ListViewItemEventArgs)'是一个事件,和   不能直接调用。使用'RaiseEvent'语句来引发   事件

2 个答案:

答案 0 :(得分:1)

在将数据分配给父控件中的嵌套控件之前,您可以在父ItemBoundData

下注册如下所示的事件
ListView f = new ListView();
f.ItemDataBound += new EventHandler<ListViewItemEventArgs>(f_ItemDataBound);

protected void f_ItemDataBound(object sender, ListViewItemEventArgs e)
{

}

答案 1 :(得分:1)

你可以这样:

  <asp:ListView onitemcommand="inner_ItemCommand" ...

受保护 / 公开项目命令方法需要:

  public void inner_ItemCommand(object sender,  ListViewCommandEventArgs e)
    {
        if (e.CommandArgument == "delete")
        {
            //do delete here
        }
    }