在 ASP.NET 3.5 中将数据集绑定到 ListView 时如何影响行内容的差异
我已将 ListView 添加到 Web 表单,并且当绑定数据集中的数据列具有值时,此代码将起作用:
<asp:ListView ID="picturesListView" runat="server"
GroupPlaceholderID="groupsGoHere"
ItemPlaceholderID="itemsGoHere"
GroupItemCount="1" >
<LayoutTemplate>
<p id="pictureList">Picture List:</p>
<ol id="imagegallery">
<asp:PlaceHolder ID="groupsGoHere" runat="server" />
</ol>
</LayoutTemplate>
<GroupTemplate>
<asp:PlaceHolder runat="server" ID="itemsGoHere" />
</GroupTemplate>
<ItemTemplate>
<li>
<a href="<%# Eval("ImageURL")%>" title="<%#Eval("ImageDesc") %>">
<%#Eval("ImageDesc")%>
</a>
</li>
</ItemTemplate>
</asp:ListView>
然后在代码隐藏文件中,我只有这两行来填充 Listview:
picturesListView.DataSource = dsImages
picturesListView.DataBind()
所有行数据集中的 ImageURL 列有一个值,但 ImageDesc 列可以为 null 或空字符串。我如何检查给定行的 ImageDesc 是否为空并构造一个“伪描述符”,例如“无标题图片编号 N”,其中 N 是数据集中的相对行号。我想我可以更改返回此数据集的存储过程......但这似乎应该是可能的。
I have added a ListView to a web form and this code works when the data columns in the bound dataset have values:
<asp:ListView ID="picturesListView" runat="server"
GroupPlaceholderID="groupsGoHere"
ItemPlaceholderID="itemsGoHere"
GroupItemCount="1" >
<LayoutTemplate>
<p id="pictureList">Picture List:</p>
<ol id="imagegallery">
<asp:PlaceHolder ID="groupsGoHere" runat="server" />
</ol>
</LayoutTemplate>
<GroupTemplate>
<asp:PlaceHolder runat="server" ID="itemsGoHere" />
</GroupTemplate>
<ItemTemplate>
<li>
<a href="<%# Eval("ImageURL")%>" title="<%#Eval("ImageDesc") %>">
<%#Eval("ImageDesc")%>
</a>
</li>
</ItemTemplate>
</asp:ListView>
Then in the codebehind file, I have just these 2 lines to populate the Listview:
picturesListView.DataSource = dsImages
picturesListView.DataBind()
All rows in the dataset have a value for the ImageURL column but the ImageDesc column can be null or an empty string. How could I check to see if ImageDesc for a given row is empty and construct a "pseudo-descriptor" such as "untitled picture no. N" where N is the relative row number in the dataset. I suppose I could change the stored procedure that returns this dataset...but this seems as if it should be possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可以做得更优雅,但应该回答你的问题:
This could be done more gracefully, but should answer your question: