2015-04-01 38 views
0

我有一個asp:Repeater具有一個DataSourceID到自定義集合。 集合類具有我想要在FooterTemplate中顯示的屬性。因爲它會根據所有項目計算一個值。中繼器的頁腳中訪問集合對象

在FooterTemplate中,有沒有一種方法可以訪問實際的集合對象?也許與容器或評估。

我沒有直接訪問數據源。我可以更改代碼以將其作爲參數,但寧可找到其他方式。

回答

0

你能用這樣的東西嗎?

rpt.DataSource = mydatasource; 
rpt.DataBind(); 

// label in footer 
var lblDateTime = rpt.FindControl("lblDateTime") as Label; 
if (lblDateTime != null) 
{ 
    lblDateTime.Text = mydatasource.First().DateChecked; 
} 

或這樣

void R1_ItemDataBound(Object Sender, RepeaterItemEventArgs e) 
{ 
    // Execute the following logic for Footer only. 
    if (e.Item.ItemType == ListItemType.Footer) { 
     // put code here to get what you want and show it in the footer 
    } 
} 
+0

感謝您的響應。我更新了這個問題。我沒有直接訪問數據源,並且.DataSource沒有任何用處,因爲它使用DataSourceID。我可以把這個集合作爲一個參數,但我想找到另一種方法。 – 2015-04-02 13:06:26