2017-01-20 166 views
0

我試圖設置第一個單選按鈕在直放站作爲託運:Repeater的Container.ItemIndex始終爲0?

<asp:RadioButton runat="server" GroupName="ApplicationOption" 
    Checked="<%# new Func<bool>(() => { 
     System.Diagnostics.Debugger.Break(); 
     return !IsPostBack && Container.ItemIndex == 0; })() %>" />  

的Debugger.Break調用導致執行在調試模式打破,所以我可以檢查值。每次它中斷時,Container.ItemIndex是0,而我期望它是0,1或2.

中繼器的數據源是3項的列表。我不想使用Code-Behind;即我想將所有內容都保存在標記中。

我缺少什麼?

回答

0

確保Repeater只有一次DataBound,並確保DataSource是您的想法。

問題在於Repeater不是DataBound一次帶有三個項目的DataSource,而是DataBound三次帶有一個DataSource項目。 :/

是的,我不知道爲什麼直放站甚至在這裏使用。

+0

此外,Repeater本身在DataBound DataList中,其ItemIndex是我需要的實際的。要獲得_that_,請使用:(Container.NamingContainer.NamingContainer作爲DataListItem).ItemIndex'。 –