tags:

views:

35

answers:

1

Hi All,

Is it possible to access a databound item via a codeblock?

For example, I am attempting to add code within an itemTemplate while the current level is not equal to the previous level.

<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>

I am recieving the following error when compiling:

CS0103: The name 'Container' does not exist in the current context

Any ideas?

+1  A: 

Container will be available only within data binding expressions (<%# %>). You can perhaps try nested repeater for what you are trying achieve.

VinayC