两个DataList嵌套的问题.

yuan243197953 2011-04-21 08:25:14
我是用DataList遍历出来所有的文章信息。然后,在里面设置一个按钮,点这个按钮的时候,显示出此条文章对应的评论信息,

我问了我的老师,他告诉我怎么绑定数据源,但是,我没弄懂的是,我第一个DataList里面有两个按钮,为什么点第一个能出来,第二个不能出来,


还有这行代码<asp:ControlParameter ControlID="DataList1" Name="aId" PropertyName="SelectedValue" Type="Int32" />

里面的PropertyName="SelectedValue"是什么意思,跟它关吗?是哪个地方。确定我点的哪个按钮也就是哪个操作,会把DataList1里面的aId绑定到SqlDataSource2的。

刚学这个东西,还没有通过三层的方法到数据库里面根据sql语句拿数据。所以,实在是搞不懂,这个DataList是怎么绑定的。。。。。

求高手指点。。。


<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server" DataKeyField="id" DataSourceID="SqlDataSource1"
OnItemCommand="DataList1_ItemCommand">
<SelectedItemTemplate>
 
</SelectedItemTemplate>
<ItemTemplate>
id:
<asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>'></asp:Label><br />
title:
<asp:Label ID="titleLabel" runat="server" Text='<%# Eval("title") %>'></asp:Label><br />
content:
<asp:Label ID="contentLabel" runat="server" Text='<%# Eval("content") %>'></asp:Label><br />
<br />
<asp:Button ID="Button1" runat="server" CommandName="select"
Text='<%# Eval("id") %>' /> 
<asp:Button ID="Button2" runat="server" CommandName="up" Text="Button" />
</ItemTemplate>
</asp:DataList>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:dateListConnectionString %>"
SelectCommand="SELECT [id], [title], [content] FROM [Article]">
</asp:SqlDataSource>

<asp:DataList ID="DataList2" runat="server" DataSourceID="SqlDataSource2">
<ItemTemplate>
id:
<asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>'></asp:Label><br />
content:
<asp:Label ID="contentLabel" runat="server" Text='<%# Eval("content") %>'></asp:Label><br />
aId:
<asp:Label ID="aIdLabel" runat="server" Text='<%# Eval("aId") %>'></asp:Label><br />
<br />
</ItemTemplate>
</asp:DataList>

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:dateListConnectionString %>"
SelectCommand="SELECT * FROM [pinglun] WHERE ([aId] = @aId)">
<SelectParameters>
<asp:ControlParameter ControlID="DataList1" Name="aId" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>

</div>
</form>
</body>
...全文
58 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
子夜__ 2011-04-21
  • 打赏
  • 举报
回复
你的第一个ID<%# Eval("id") %>绑定帖子的ID

CommandName="select"

制定你后台触发的事件。

其实用原始的SQL写一遍 应该就很透彻了。

62,266

社区成员

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

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

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

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