How do I access a c# variable's value in an .aspx page?

后端 未结 4 1346
春和景丽
春和景丽 2021-01-02 18:38

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

we need to access the c# variable in .aspx page at the time

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-02 19:21

    You'll need something on the page that can be data bound. Bind that object to it's data source and then you can do an "Eval" on it in the .aspx.

    For example, if you have bound your control (presumably in the code-behind) to an object that has a property called "Author", you can display it in the following manner:

    
       Author:
       <%#Eval("Author")%>
    
    

    The Table in this example is part of an Accordion control where the ".DataSource" property was set to a generic list of objects, of which "Author" was one of the properties.

提交回复
热议问题