【问题标题】:itemdatabound event of a nested listview嵌套列表视图的 itemdatabound 事件
【发布时间】:2012-03-17 19:10:08
【问题描述】:

我有一个嵌套列表视图,我在父“ItemDataBound”事件上进行数据绑定,但我如何访问/注册嵌套列表视图的 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(sender As Object, e As System.Web.UI.WebControls.ListViewItemEventArgs)' 是一个事件,并且 不能直接调用。使用“RaiseEvent”语句来引发 事件。

【问题讨论】:

    标签: asp.net listview nested itemdatabound


    【解决方案1】:

    在将数据分配给父控件中的嵌套控件之前,您可以在父控件ItemBoundData 下注册如下所示的事件

    ListView f = new ListView();
    f.ItemDataBound += new EventHandler<ListViewItemEventArgs>(f_ItemDataBound);
    
    protected void f_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
    
    }
    

    【讨论】:

      【解决方案2】:

      你可以这样:

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

      protected / public item 命令方法需要:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-10-27
        • 2012-03-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-02
        • 1970-01-01
        相关资源
        最近更新 更多