“容器在当前上下文中不存在”错误 [英] "Container does not exist in current context" Error

查看:66
本文介绍了“容器在当前上下文中不存在”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是asp.net的新手。我正在开发一个Web应用程序,我想在其中显示与搜索查询相关的网页上的图像。我已将数据路径存储在db&磁盘上的图像。用于搜索的SQL查询也正常工作。



要在网页上显示图像,在aspx页面上我写了以下代码:



 <   asp:DataList     ID   =  dataList1    runat   = 服务器    GridLines   = 两者   高度  =  105px    Horizo​​ntalAlign   = 中心    RepeatColumns   =  4    RepeatDirection   = 水平    RepeatLayout   =    宽度  =  243px >  
< ItemTemplate >
< img alt = image1 src = < span class =code-keyword> <% DataBinder.Eval(Container.DataItem, < span class =code-string> path); %>
< / ItemTemplate>
< AlternatingItemTemplate>
< img alt = image1 src = <% DataBinder.Eval(Container.DataItem, path); %>

< / AlternatingItemTem plate >
< / asp:DataList >





其中,path是列中的一个db table.In后面的代码我使用的是数据集对象&将它绑定到dalaList1.But我在aspx页面上收到错误当前上下文中不存在名称'Container'。



任何人都可以帮助我请问?

解决方案

如果你是非常新的ASP.NET,这对你来说是一个疯狂的任务。我假设你在课堂上,为什么你的老师给你这么复杂的任务?或者您是否已经知道SQL和C#或VB.NET?



您使用#而不是%来指定在数据上下文中运行的代码。 />


[更新]



您在绑定语法中错过了#。 />
语法是,

<%#DataBinder.Eval(Container.DataItem,Path)%>


 <   asp:DataList     ID   =  dataList1    runat   = 服务器    GridLines   = 两者   高度  =  105px    Horizo​​ntalAlign   = 中心    RepeatColumns   =  4    RepeatDirection   = 水平    RepeatLayout   =    宽度  =  243px >  
< ItemTemplate >
< img alt = image1 src =' <%#DataBinder.Eval( Container.DataItem, path%> ' / >
< / ItemTemplate >
< AlternatingItemTemplate < span class =code-keyword>>
< img alt = image1 src =' <%#DataBinder.Eval(Container.DataItem, path%> ' / >
< / AlternatingItemTemplate >
< / asp:DataList >


< asp:DataList ID =   dataList1 runat =  服务器 GridLines =  两者高度=   105px Horizo​​ntalAlign =   Center RepeatColumns =   4 RepeatDirection =  水平 RepeatLayout =  宽度=   243px >  
< ItemTemplate>
< img alt = image1 src = ' <%#DataBinder.Eval(Container.DataItem,path)%>' />
< / ItemTemplate >
< AlternatingItemTemplate>
< img alt = image1 src = ' <%#DataBinder.Eval(Container.DataItem,path)%>' />
< / AlternatingItemTemplate >
< / asp:DataList >


Hi all,
I am very new to asp.net. I am developing a web application in which I want to show the images on web page related to search query. I have stored image path in db & images on disk.The SQL query for search is also working fine.

To show images on web page,on aspx page I have written following code:

<asp:DataList ID="dataList1" runat="Server" GridLines="Both" Height="105px" HorizontalAlign="Center" RepeatColumns="4" RepeatDirection="Horizontal" RepeatLayout="Table" Width="243px">
<ItemTemplate>
    <img alt="image1" src="<% DataBinder.Eval(Container.DataItem,"path");%>
</ItemTemplate>
<AlternatingItemTemplate>
    <img alt="image1" src="<% DataBinder.Eval(Container.DataItem,"path");%>"

</AlternatingItemTem plate>
</asp:DataList>



where,"path" is the column in a db table.In code behind I am using dataset object & binding it to dalaList1.But I am getting the error "The name 'Container' does not exist in the current context" on the aspx page.

Can anyone help me out please?

解决方案

If you're 'very new to ASP.NET', this is an insane task for you to undertake. I assume you're in a class, why is your teacher giving you such a complex task ? Or did you know SQL and C# or VB.NET already ?

You use a #, not a %, to specify code that runs in a data context.

[UPDATE]

You missed # in the binding syntax.
Syntax is,
<%# DataBinder.Eval(Container.DataItem, "Path") %>


<asp:DataList ID="dataList1" runat="Server" GridLines="Both" Height="105px" HorizontalAlign="Center" RepeatColumns="4" RepeatDirection="Horizontal" RepeatLayout="Table" Width="243px">
    <ItemTemplate>
          <img alt="image1" src='<%# DataBinder.Eval(Container.DataItem,"path") %>'/>
    </ItemTemplate>
    <AlternatingItemTemplate>
          <img alt="image1" src='<%# DataBinder.Eval(Container.DataItem,"path") %>' />
    </AlternatingItemTemplate>
</asp:DataList>


<asp:DataList ID="dataList1" runat="Server" GridLines="Both" Height="105px" HorizontalAlign="Center" RepeatColumns="4" RepeatDirection="Horizontal" RepeatLayout="Table" Width="243px">
    <ItemTemplate>
          <img alt="image1" src='<%# DataBinder.Eval(Container.DataItem,"path") %>'/>
    </ItemTemplate>
    <AlternatingItemTemplate>
          <img alt="image1" src='<%# DataBinder.Eval(Container.DataItem,"path") %>' />
    </AlternatingItemTemplate>
</asp:DataList>


这篇关于“容器在当前上下文中不存在”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆