2012-03-17 96 views
1

我有一個嵌套的列表視圖,我databind父'ItemDataBound'事件,但我如何訪問/註冊嵌套listview的itemdatabound事件?itemdatabound嵌套列表視圖事件

謝謝!

編輯

我父母的ListView的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'語句來提高 事件。

回答

1

之前,你的父母控制分配數據給嵌套的控制,你可以像下面的活動你的父母下ItemBoundData

ListView f = new ListView(); 
f.ItemDataBound += new EventHandler<ListViewItemEventArgs>(f_ItemDataBound); 

protected void f_ItemDataBound(object sender, ListViewItemEventArgs e) 
{ 

} 
+0

感謝您的指針。儘管我得到一個錯誤;請參閱我的編輯 – Dooie 2012-03-17 20:14:41

1

您可以在此註冊:

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

保護/public item命令方法需要:

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