datalist嵌套,内层datalist获取外层的值做判断

滇中倦客 2012-03-17 10:05:51
本人想做一个类似于QQ空间显示评论的功能,外层是所有的上传的照片动态,每个照片下面有个datalist显示该心情二部分评论!出错了,麻烦大侠指点一下!
错误提示:当前上下文中不存在名称“photoid”
源错误:
行 49: </ItemTemplate>
行 50: </asp:DataList>
行 51: <asp:SqlDataSource ID="SqlDataSource3" runat="server"
行 52: SelectCommand='<%# "SELECT TOP (4) comment.[content], comment.commentdata, comment.usernumber, userinfo.username, userinfo.picture FROM comment INNER JOIN userinfo ON comment.usernumber = userinfo.usernumber WHERE (comment.photoid = "+Eval(photoid)+") ORDER BY comment.commentdata DESC"%>'
行 53: ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>">

代码:

<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource2">
<ItemTemplate>
<table style="width:596px;max-height:50px">
<tr style="width:596px;max-height:80px" valign="top">
<td style="width:50px">
<a href="home_pre.aspx?usernumber=<%# Eval("usernumber")%>&&photoid=<%#Eval("photoid") %>">
<asp:Image ID="Image4" runat="server" Height="60px" Width="50px" ImageUrl='<%# Eval("picture") %>' ImageAlign="Middle" /></a>
</td>
<td style="height:50px;width=56px" align="left">
<a href="home_pre.aspx?usernumber=<%# Eval("usernumber")%>">
<asp:Label ID="yonghu3" runat="server" Text='<%#Eval("username") %>' ForeColor="#0099FF"></asp:Label>上传照片到:</a>
<asp:Label ID="xiangcemingcheng" runat="server" Text='<%# Eval("phototitle") %>'></asp:Label>  
<div style="text-align:center">
<asp:Image ID="Image6" runat="server" ImageUrl='<%#Eval("url") %>' ImageAlign="Middle"/>
</div>
<asp:Label ID="photoid" runat="server" Text='<%#Eval("photoid") %>' Visible="false"></asp:Label>
</td>
</tr>
<tr>
<td style="width:50px; height:16px"></td>
<td>
<asp:DataList ID="DataList_xcpl" runat="server" DataSourceID="SqlDataSource3">
<ItemTemplate>
<table style="width:536px; max-height:50px;text-align:right">
<tr style="width:536px;max-height:80px; text-align:left" valign="top">
<td style="width: 30px;text-align:left" valign="top">
<a href='home_pre.aspx?usernumber=<%# Eval("usernumber")%>'>
<asp:Image ID="Image3" runat="server" Height="36px" Width="30px" ImageUrl='<%# Eval("picture") %>' ImageAlign="Middle" /></a>
</td>
<td style="height:50px; max-height:506px; " align="left">
<a href='home_pre.aspx?usernumber=<%# Eval("usernumber")%>'>
<asp:Label ID="Label6" runat="server" Text='<%# Eval("username") %>' ForeColor="#0099FF"></asp:Label>评论说:</a>
<asp:Label ID="Label7" runat="server" Text='<%# Eval("content") %>'></asp:Label>    <asp:Label
ID="Label9" runat="server" Text='<%# Eval("commentdata") %>' ForeColor="Gray"></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
SelectCommand='<%# "SELECT TOP (4) comment.photoid, comment.[content], comment.commentdata, comment.usernumber, userinfo.username, userinfo.picture FROM comment INNER JOIN userinfo ON comment.usernumber = userinfo.usernumber WHERE (comment.photoid = "+Eval(photoid)+") ORDER BY comment.commentdata DESC"%>'
ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>">
</asp:SqlDataSource>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
SelectCommand="SELECT TOP (4) userinfo.username, userinfo.picture, photo.photoid, photo.url, photo.photodata FROM userinfo INNER JOIN photo ON userinfo.usernumber = photo.usernumber"
ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>">
</asp:SqlDataSource>
...全文
80 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
滇中倦客 2012-03-18
  • 打赏
  • 举报
回复
不行啊 ~~~

<' 附近有语法错误。
以 'SELECT TOP (4) comment.photoid, comment.[content], comment.commentdata, userinfo.username, userinfo.picture FROM comment INNER J' 开头的 标识符 太长。最大长度为 128。
porschev 2012-03-18
  • 打赏
  • 举报
回复

SelectCommand='<%# "SELECT TOP (4) comment.[content], comment.commentdata, comment.usernumber, userinfo.username, userinfo.picture FROM comment INNER JOIN userinfo ON comment.usernumber = userinfo.usernumber WHERE (comment.photoid = "+Eval(photoid)+") ORDER BY comment.commentdata DESC"%>'

------》

SelectCommand='<%# "SELECT TOP (4) comment.[content], comment.commentdata, comment.usernumber, userinfo.username, userinfo.picture FROM comment INNER JOIN userinfo ON comment.usernumber = userinfo.usernumber WHERE (comment.photoid = "+Eval("photoid")+") ORDER BY comment.commentdata DESC"%>'


-------------------------------
这里这么长建议后来写个带object参数的方法,比如:GetStr

前台<%# GetString(Eval("字段")) %>

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧