“容器在当前上下文中不存在”错误

编程入门 行业动态 更新时间:2024-10-26 10:28:37
本文介绍了“容器在当前上下文中不存在”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我是asp的新手。我正在开发一个Web应用程序,我想在其中显示与搜索查询相关的网页上的图像。我已将数据路径存储在db&磁盘上的图像。用于搜索的SQL查询也正常工作。 要在网页上显示图像,在aspx页面上我写了以下代码:

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

更多推荐

“容器在当前上下文中不存在”错误

本文发布于:2023-11-09 15:12:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572699.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上下文   中不   容器   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!