信息发布→ 登录 注册 退出

asp.net 获取文件夹中的图片的代码

发布时间:2026-01-11

点击量:
前台:
复制代码 代码如下:
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="5"
CellSpacing="25">
<ItemTemplate>
<img src="<%# Eval("FullName") %>" width="50" height="50" border="0" >
</ItemTemplate>
</asp:DataList>

后台代码:
复制代码 代码如下:
string path = Server.MapPath("img");//获取img文件夹的路径
Response.Write(path);
DirectoryInfo di = new DirectoryInfo(path);
//DataList1.DataSource = di.GetFiles("*.jpg");只获取jpg图片
DataList1.DataSource = di.GetFiles();//获取文件夹下所有的文件
DataList1.DataBind();
标签:# asp  # Response  # MapPath  # DirectoryInfo  # Write  # ID  # server  # runat  # DataList  # span  # BR  # 文件夹  # lt  # ItemTemplate  # gt  # src  # img  # Horizontal  # RepeatDirection  # CellSpacing  # RepeatColumns  # 图片  
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!