2013-07-09 44 views
0

我有一箇中繼器:傳遞當前項目的功能

<asp:Repeater runat="server" ID="RepeaterCategorie"> 
    <ItemTemplate> 
     <%#((isBlocked()) ? "true" : "false") %> 
    </ItemTemplate> 
</asp:Repeater>   

,我呼籲的.cs的功能。我想將當前項目(我的意思是,當前項目在數據源列表中迭代)傳遞給該函數。如何在不通過isBlocked函數傳遞參考的情況下執行此操作?

+0

爲什麼要那樣做,作爲中繼器的一部分嗎?爲什麼不在頁面上顯示之前進行此處理? –

+0

因爲屬性不在我迭代的Object中。 – markzzz

回答

2

HTML

<asp:Repeater runat="server" ID="RepeaterCategorie" 
    OnItemDataBound="RepeaterCategorie_ItemDataBound"> 
    <ItemTemplate> 
     <asp:Label runat="server" Id="lblBool"></asp:Label> 
    </ItemTemplate> 
</asp:Repeater> 

CS

protected void RepeaterCategorie_ItemDataBound(
    object sender, RepeaterItemEventArgs e) 
{ 
    if (e.Item.ItemType == ListItemType.Item || 
     e.Item.ItemType == ListItemType.AlternatingItem) 
    { 
     var lblBool = (Label)e.Item.FindControl("lblBool"); 
     lblBool.Text = isBlocked(sender, e) ? "true" : "false"; 
    } 
} 
+0

正如我所說的,「沒有通過isBlocked函數傳遞參考」 – markzzz

+0

@markzzz:對不起,錯過了那個部分,因爲沒什麼意義;)你能解釋一下爲什麼你試圖做到這一點。這不僅是好奇心,它可以幫助我提供解決方案。 –

+0

例如在.cs上的函數上使用'object sender,EventArgs e':它應該明白是誰調用了該函數並傳遞了該對象! – markzzz