asp.net c# 怎样在主页显示某个文件夹里的所有图片

我想把uploadfiles里的所有图片(jpeg)在default.aspx里显示出来,uploadfiles里的图片是会有上传的,所以要先读取文件夹里的图片在显示,最... 我想把uploadfiles里的所有图片(jpeg)在default.aspx里显示出来,uploadfiles里的图片是会有上传的,所以要 先读取文件夹里的图片 在显示,最好是 竖的 排一列。求大神 需要 完整的 代码等 好的话有加分 急!!! 展开
 我来答
万菡uU
2013-06-07 · TA获得超过258个赞
知道小有建树答主
回答量:379
采纳率:66%
帮助的人:379万
展开全部

思路:1.文件上传的时候DB记录文件路径。

           2.default.aspx增加datalist控件设计模版

前台如:

<asp:DataList ID="DataList1" runat="server" Height="30px" RepeatColumns="1" 
                        Width="705px" CssClass="style4">
                        <ItemTemplate>
                            <table cellpadding="0" cellspacing="0" class="" 
                                style="width:644px; height: 54px;">
                                <tr>
                                    <td align="left" colspan="2" 
                                        style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; padding-top: 1px; height: 35px; ">
                                        &nbsp;<asp:Image ID="Image1" runat="server" Height="248px" 
                                            ImageUrl='<%# DataBinder.Eval(Container.DataItem,"Imgurl") %>' 
                                            Width="428px" />
                                    </td>
                                </tr>
                                <tr>
                                    <td align="left" class=" fist_lines4" 
                                        style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; padding-top: 3px; ">
                                        &nbsp;&nbsp;图片名称:</td>
                                    <td align="left" class="tdd-gray-b fist_lines2" 
                                        style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; padding-top: 3px; height: 29px;">
                                        &nbsp;
                                        <asp:Label ID="Label4" runat="server" Font-Bold="True" Font-Size="10pt" 
                                            Text='<%# DataBinder.Eval(Container.DataItem,"imgname") %>'></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="left" class=" fist_lines4" 
                                        
                                        style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; padding-top: 3px; " 
                                        bgcolor="#CCFFFF">
                                        &nbsp; 设备名称:</td>
                                    <td align="left" class=" fist_lines4" 
                                        
                                        style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; padding-top: 3px" 
                                        bgcolor="#CCFFFF">
                                        &nbsp;
                                        <asp:Label ID="Label5" runat="server" Font-Size="10pt" 
                                            Text='<%# DataBinder.Eval(Container.DataItem,"Sbname") %>' 
                                            ForeColor="#006600"></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="left" class=" fist_lines4" 
                                        style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; padding-top: 3px; ">
                                        &nbsp; 上传人员:&nbsp;</td>
                                    <td align="left" class=" fist_lines4" 
                                        style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; padding-top: 3px">
                                        &nbsp;
                                        <asp:Label ID="Label6" runat="server" Font-Size="10pt" 
                                            Text='<%# DataBinder.Eval(Container.DataItem,"Sysemp") %>'></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </asp:DataList>

后台:

 private void imgdata(string sbid)
    {
        Label7.Text = sbid;
        sql = "select * from sb_imgupload_t where sbid='" + sbid + "' ";
        ds = MySqlHelper.ExecuteDataset(constr, sql);
        if (ds.Tables[0].Rows.Count > 0)
        {
            
            DataList1.DataSource = ds.Tables[0];
            DataList1.DataBind();
        }
        else
        {
            DataList1.DataSource = null;
            DataList1.DataBind();
            
        }
    }

效果:

航猪猪的店铺
2013-06-07
知道答主
回答量:19
采纳率:0%
帮助的人:3.9万
展开全部
明天给你回答,现在只能给你一个思路,就是可以用一个控件
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式