使用Repeater模版绑定数据时,使用 <%# ((DataRowView)Container.DataItem)["name"] %> 语句来显示绑定的数据。
只能在<%# ... %>中使用((DataRowView)Container.DataItem)["name"],如果在<% ... %>使用就会提示错误:CS0246: 找不到类型或命名空间名称“Container”(是否缺少 using 指令或程序集引用?)据说是因为<%# ... %>中使用的是局部变量;而<% ... %>使用的是全局变量,因此找不到Container。那么,这里的Container是引用自哪里呢?从哪里来?
只能在<%# ... %>中使用((DataRowView)Container.DataItem)["name"],如果在<% ... %>使用就会提示错误:CS0246: 找不到类型或命名空间名称“Container”(是否缺少 using 指令或程序集引用?)据说是因为<%# ... %>中使用的是局部变量;而<% ... %>使用的是全局变量,因此找不到Container。那么,这里的Container是引用自哪里呢?从哪里来?
http://blog.joycode.com/saucer/archive/2004/04/14/19456.aspx
看了你的Blog
System.Web.UI.WebControls.DataGridItem Container;
既然Container是个局部变量,那么能否在<% ... %>中直接引用呢?
<Columns>
<asp:TemplateColumn HeaderText="Name">
<ItemTemplate><%# DataBinder.Eval(Container.DataItem,"Name")%></ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
绑定属性:<%#Property%>
绑定集合:<asp:dataGrid id = "dg" datasource="<%#mydataview%>" runat=server/>
绑定表达式:<%#container.dataItem%>
绑定函数结果:<%getForm(user)%>
从上面的例子可以看出,绑定的数据包含在〈%#%〉标签之内,这与〈%%〉标签有些相
似,千万小要以为它们的“样子”差不多就认为它们的功能也是一样的,〈%#%〉与〈%%〉
之间的差别非常大。〈%%〉之间的代码将会被直接执行.而〈%#%〉之间包含的代码、仅仅
在DataBind()方法调用后,才会被执行。Page以及所有server控件都拥有DataBind万法。
你的意思是说<% %>执行的时候 container.dataItem 还不存在吗?
%>
<table class="gueststyleline" width="100%" border="0" cellpadding="1" cellspacing="0" >
<tr>
<td>
<table class="gueststylerebg" width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td valign="top">
<table width="100%" border="0" cellpadding="2" cellspacing="0" style="TABLE-LAYOUT: fixed" class="replytext">
<tr>
<td>站长回复:</td>
</tr>
<tr>
<td valign="bottom">
<%# ((DataRowView)Container.DataItem)["reply"] %></td>
</tr>
<tr align="right">
<td valign="bottom" align="right">
<hr class="gueststylehr" size="0.1" width="70%" noshade align="right" >
回复于: <%# ((DataRowView)Container.DataItem)["redate"] %></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<% }%>
%>
<table class="gueststyleline" width="100%" border="0" cellpadding="1" cellspacing="0" >
<tr>
<td>
<table class="gueststylerebg" width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td valign="top">
<table width="100%" border="0" cellpadding="2" cellspacing="0" style="TABLE-LAYOUT: fixed" class="replytext">
<tr>
<td>站长回复:</td>
</tr>
<tr>
<td valign="bottom">
<%# ((DataRowView)Container.DataItem)["reply"] %></td>
</tr>
<tr align="right">
<td valign="bottom" align="right">
<hr class="gueststylehr" size="0.1" width="70%" noshade align="right" >
回复于: <%# ((DataRowView)Container.DataItem)["redate"] %></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<% }%>
<asp:PlaceHolder id="ph" runat="server" Visible='<%# ((DataRowView)Container.DataItem)["reply"].ToString().Length == 0 %>'><table class="gueststyleline" width="100%" border="0" cellpadding="1" cellspacing="0" >
<tr>
<td>
<table class="gueststylerebg" width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td valign="top">
<table width="100%" border="0" cellpadding="2" cellspacing="0" style="TABLE-LAYOUT: fixed" class="replytext">
<tr>
<td>站长回复:</td>
</tr>
<tr>
<td valign="bottom">
<%# ((DataRowView)Container.DataItem)["reply"] %></td>
</tr>
<tr align="right">
<td valign="bottom" align="right">
<hr class="gueststylehr" size="0.1" width="70%" noshade align="right" >
回复于: <%# ((DataRowView)Container.DataItem)["redate"] %></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table></asp:PlaceHolder>