【问题标题】:how to get parent repeater item from child repeater?如何从子中继器获取父中继器项目?
【发布时间】:2011-03-18 04:21:38
【问题描述】:

我有两个嵌套的中继器。意味着有一个中继器,在里面我有另一个中继器。

我想要以下格式的数据:

*Transaction Id:1xasd2*
Product1  2  500
*Transaction Id:2asd21*
Product2  1  100
Product3  2  200

那么我该如何实现呢?

【问题讨论】:

  • 您目前的嵌套中继器设计有什么问题?
  • 我希望当我绑定子中继器时我想要父级的事务 ID。所以我怎样才能得到它???

标签: c# asp.net repeater


【解决方案1】:

可以使用:

var repeater = (Repeater)sender;
var parentItem = (RepeaterItem)repeater.NamingContainer;
<Object> parentDataItem = parentItem.DataItem as <Object>;
(parentDataItem.property)

成功了!

【讨论】:

    【解决方案2】:

    我想你正在寻找:

    Protected Sub rptMaster_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptMaster.ItemDataBound
        Dim drv As DataRowView = e.Item.DataItem
        Dim rptChild As Repeater = CType(e.Item.FindControl("rptChild"), Repeater)
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
                'Get TransactionID here from master repeater
                Dim lblTransactionID  As Label = drv("TransactionID")
                'bind child repeater here
                rptChild.DataSource = GetData()
                rptChild.DataBind()
        End If
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多