Dooie
Dooie

Reputation: 1669

itemdatabound event of a nested listview

I have a nested listview which I databind on the parent 'ItemDataBound' event, but how do i access/register the nested listview's itemdatabound event?

Thanks!

Edits

My parent listview itemdatabound now looks like so,

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

but i get an error

BC32022: 'Public Event ItemDataBound(sender As Object, e As System.Web.UI.WebControls.ListViewItemEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

Upvotes: 1

Views: 1905

Answers (2)

Harry Sarshogh
Harry Sarshogh

Reputation: 2197

You can this :

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

protected / public item command method need :

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

Upvotes: 1

Pankaj
Pankaj

Reputation: 10115

Before assigning the data to nested control in your parent control you can register the event like below under your parent ItemBoundData

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

protected void f_ItemDataBound(object sender, ListViewItemEventArgs e)
{

}

Upvotes: 1

Related Questions