大家好, 我是asp的新手。我正在开发一个Web应用程序,我想在其中显示与搜索查询相关的网页上的图像。我已将数据路径存储在db&磁盘上的图像。用于搜索的SQL查询也正常工作。 要在网页上显示图像,在aspx页面上我写了以下代码:
< asp:DataList ID = dataList1 runat = 服务器 GridLines = 两者 高度 = 105px HorizontalAlign = 中心 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 HorizontalAlign = 中心 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 HorizontalAlign = 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>更多推荐
“容器在当前上下文中不存在”错误
发布评论