2010-09-01 30 views
1

是否可以通過代碼塊訪問數據綁定項目?是否可以通過代碼塊訪問數據綁定項目

例如,我試圖在itemTemplate中添加代碼,而當前級別不等於先前的級別。

CS0103:

<itemTemplate> 
<% 
// Need to ensure Container exists in current context 
// Get my previous level (example: 3) 
// Get my current level (example: 1) 
// Loop from my current level to my previous level and add 
// </ul></li> for each level 

int previousLevel = Container.Menu.DataSource.Rows[Container.Index - 1]["Level"]; 
int currentLevel = Container.Menu.DataSource.Rows[Container.Index]["Level"]; 
while(currentLevel != previousLevel) 
{ 
%> 
    </ul> 
     </li> 
<% 
     currentLevel++; 
} 
%> 
</itemTemplate> 

編譯時我recieving以下錯誤 '容器' 的名稱在目前情況下

任何想法不 存在嗎?

回答

1

容器只能在數據綁定表達式中使用(<%# %>)。你也許可以嘗試使用嵌套式中繼器來達到你想要達到的效果。

相關問題