如何在asp.net中动态生成无序列表? [英] How to generate unordered list dynamically in asp.net?
问题描述
我要生成包含标记为显示在我的数据库图像的无序列表,我来看看项目符号列表,但它不具有图像的工作。如何动态地从数据库中生成的结果是,对于例如,如果我有在数据库6图像然后我想它一定会产生像这样的列表中。
< UL ID => <立GT;< IMG SRC =资源/ img14.jpgALT =标题=/>< /李> <立GT;< IMG SRC =资源/ img15.jpgALT =标题=/>< /李> <立GT;< IMG SRC =资源/ img17.jpgALT =标题=/>< /李> <立GT;< IMG SRC =资源/ img2.jpgALT =标题=/>< /李> <立GT;< IMG SRC =资源/ img5.jpgALT =标题=/>< /李> <立GT;< IMG SRC =资源/ img3.jpgALT =标题=/>< /李>< / UL>
表结构
用户名称为nvarchar(50)
图片路径为nvarchar(MAX)
有关你正在尝试实现,这将是最好的,最简单的办法使用< ASP:ListView控件>
控制。
有一个很好的教程在这里如何使用它,pretty很多类似于你在做什么<一个href=\"http://weblogs.asp.net/scottgu/archive/2007/08/10/the-asp-listview-control-part-1-building-a-product-listing-page-with-clean-css-ui.aspx\">http://weblogs.asp.net/scottgu/archive/2007/08/10/the-asp-listview-control-part-1-building-a-product-listing-page-with-clean-css-ui.aspx
这将主要涉及您创建一个&LT; ASP:ListView控件&GT;
控制等;
&LT; ASP:ListView控件ID =ListView1的=服务器&GT;
&LT;&LayoutTemplate模板GT;
&LT; UL&GT;
&LT; ASP:占位符ID =itemPlaceholder=服务器/&GT;
&LT; / UL&GT;
&LT; / LayoutTemplate模板&GT;
&LT;&ItemTemplate中GT;
&LT;立GT;
&LT; IMG SRC ='&LT;%#的eval(PicPath)%&GT;' ALT ='&LT;%#的eval(用户名)%&GT;' /&GT;
&LT; /李&GT;
&LT; / ItemTemplate中&GT;
&LT; EmptyDataTemplate&GT;
&LT; P&GT;没有此处&lt; / P&GT;
&LT; / EmptyDataTemplate&GT;
&LT; / ASP:的ListView&GT;
那么你的数据绑定到它。
this.ListView1.DataSource = YourDataSource;
this.ListView1.DataBind();
I want to generate a unordered list which contains tag for showing images in my database, I take a look at bulleted list, but it is not working with image. How can i dynamically generate it from the results in a database, for eg, if i have 6 images in data base then i want the list which generates must look like this.
<ul id="">
<li><img src="Resources/img14.jpg" alt="" title=""/></li>
<li><img src="Resources/img15.jpg" alt="" title=""/></li>
<li><img src="Resources/img17.jpg" alt="" title=""/></li>
<li><img src="Resources/img2.jpg" alt="" title=""/></li>
<li><img src="Resources/img5.jpg" alt="" title=""/></li>
<li><img src="Resources/img3.jpg" alt="" title=""/></li>
</ul>
Table Structure
User Name nvarchar(50)
Pic Path nvarchar(MAX)
For what you are trying to achieve, it would be best and easiest just to use a <asp:ListView>
control.
There is a good tutorial here on how to use it, and pretty much similar to what you are doing http://weblogs.asp.net/scottgu/archive/2007/08/10/the-asp-listview-control-part-1-building-a-product-listing-page-with-clean-css-ui.aspx
It would basically involve you creating a <asp:ListView>
control like;
<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<li>
<img src='<%#Eval("PicPath")%>' alt='<%#Eval("UserName")%>' />
</li>
</ItemTemplate>
<EmptyDataTemplate>
<p>Nothing here.</p>
</EmptyDataTemplate>
</asp:ListView>
Then binding your data to it.
this.ListView1.DataSource = YourDataSource;
this.ListView1.DataBind();
这篇关于如何在asp.net中动态生成无序列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!