显示来自同一数据列表中数据库的文件夹和值的图像 [英] Showing image from folder and values from database in the same datalist

查看:67
本文介绍了显示来自同一数据列表中数据库的文件夹和值的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我想显示我已上传到文件夹的图片,并从Datalist中的数据库中获取值。我面临的问题是我只能将图像绑定到datalist。如何同时绑定图像和数据库表??



i我在页面上调用此函数



 private void bindDatalist()
{
DirectoryInfo dir = new DirectoryInfo(MapPath(Thumb));
FileInfo [] files = dir.GetFiles();
ArrayList listItems = new ArrayList();
foreach(文件中的FileInfo信息)
{
listItems.Add(info);
}
dtlistMedia.DataSource = listItems;
dtlistMedia.DataBind();





这是我的.aspx代码



 <   asp:DataList     ID   =  dtlistMedia    runat   =  server    RepeatColumns   =  4    CellPadding   =  6   >  
< ItemTemplate >
< asp:Image 宽度 = 300px 高度 = 200px ID = Image1 ImageUrl =' < span class =code-pagedirective><% #Eval( 名称 〜/ Thumb / {0}%> ' runat = server / >
< ; br / < span class =code-keyword>>
< asp:HyperLink ID = HyperLink1 文本 =' <% #Bind( 名称%> ' NavigateUrl =' <% #Bind( < span class =code-string>名称 〜/ Thumb / {0}%> ' runat = server / >
< br / >
< asp:标签 runat = server 文字 =' <% #Eval( 费用)< span class =code-pagedirective>%> ' > < / asp:标签 >
< / ItemTemplate >
< ItemStyle BorderColor = 布朗 < span class =code-attribute> BorderStyle = dotted BorderWidth = 3px Horizo​​ntalAlign = 中心

VerticalAlign = < span class =code-keyword>底部 / >







问题是如何o绑定datalist。这里我已将它绑定到列表项,但是listitem只包含图像而不是存储在数据库中的成本。



plz帮我解决

解决方案

Datalist在给定时间不能有多个数据源。您必须将目录和数据库中的数据整理为一个,然后将其用作数据源。

分别检索数据,将数据合并到第三个,这应该是好的。


如果你想要从文件夹显示图像然后将图像存储在文件夹中并将图像名称存储在数据库中

并使用以下代码显示图像

< asp:图像 宽度 = 300px 高度 = 200px ID = Image1 ImageUrl =' <% #Eval( ImageName ,, 〜/ ProductImages / {0} runat = server />


EVal( ImageName

的列名和〜/ ProductImages 文件夹名称


我想显示我已上传到文件夹中的图片并获取值来自Datalist中的数据库。我面临的问题是我只能将图像绑定到datalist。如何同时绑定图像和数据库表?





来自数据库的ImageName

这里来自文件夹的图片

linkbutton重定向特定页面





i需要这样输出,,,,





请帮我

Hi all!!

I want to show image that i have upload into a folder and fetch the values from database inside a Datalist. The problem that i am facing is that i am able to bound only images to the datalist. how to bind both images and database table at the same time??

i am calling this function on pageload

private void bindDatalist()
    {
        DirectoryInfo dir = new DirectoryInfo(MapPath("Thumb"));
        FileInfo[] files = dir.GetFiles();
        ArrayList listItems = new ArrayList();
        foreach (FileInfo info in files)
        {
            listItems.Add(info);
        }
        dtlistMedia.DataSource = listItems;
        dtlistMedia.DataBind();



this is my .aspx code

<asp:DataList ID="dtlistMedia" runat="server" RepeatColumns="4" CellPadding="6" >
           <ItemTemplate>
            <asp:Image Width="300px" Height="200px" ID="Image1" ImageUrl='<%# Eval("Name", "~/Thumb/{0}") %>' runat="server"  />
            <br />
                     <asp:HyperLink ID="HyperLink1" Text='<%# Bind("Name") %>' NavigateUrl='<%# Bind("Name", "~/Thumb/{0}") %>' runat="server"/>
          <br />
         <asp:Label runat="server" Text='<%#Eval("Cost") %>'></asp:Label>
           </ItemTemplate>
           <ItemStyle BorderColor="Brown" BorderStyle="dotted" BorderWidth="3px" HorizontalAlign="Center"

VerticalAlign="Bottom" />




the problem is that how to bind the datalist. here i have bound it to listitems but listitem only contains images not the cost which is stored in database.

plz help me out

解决方案

You cannot have multiple datasources at a given time for the Datalist. You have to collate the data from directory and database into one and then use that as a datasource.
Retrieve the data separately, merge the data into a third and it should be good to go.


If your want to show Image from Folder Then store the image in Folder and store image name in database

And use following code to show the image

 <asp:Image Width="300px" Height="200px" ID="Image1" ImageUrl='<%# Eval("ImageName", , "~/ProductImages/{0}" runat="server"  />


EVal("ImageName" is a Column name of Table

And ~/ProductImages is  a folder name in your website


I want to show image that i have uploaded into a folder and fetch the values from database inside a Datalist. The problem that i am facing is that i am able to bound only images to the datalist. how to bind both images and database table at the same time??


ImageName from database
here image from folder
linkbutton to redirect specific page


i need output this way,,,,


pls help me


这篇关于显示来自同一数据列表中数据库的文件夹和值的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆