Click here to Skip to main content
15,914,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
From a table 'item', I use a column name 'picture_file' that holds images to be shown in datalist.

I use the following code. It works without errors or exception but image is not displayed.
ASP.NET
<asp:DataList ID="Datalist1" runat="server" DataKeyField="item_code" RepeatDirection="Horizontal"
    RepeatLayout="Table"
    datasourceid="sqldatasource1">
    <HeaderTemplate>

    </HeaderTemplate>
    <ItemTemplate>

    Item code:
    <asp:Label Id="Itmcodelbl" runat="server" Text='<%#Eval("item_code") %>'>
    </asp:Label>

    <br />

    Item Name:
    <asp:Label Id="Itmnamelbl" runat="server" Text='<%#Eval("item_name") %>'>
    </asp:Label>
    <br />


Particulars:
ASP.NET
<br />
<asp:TextBox Id="TB1" runat="server" Text='<%#Eval("item_desc") %>'
    Height="94"   ReadOnly="true"  TextMode="MultiLine"  BorderStyle="None">
</asp:TextBox>
<br />
<img src='<%# Eval("Picture_file") %>' style="height:100px;width:100px;border:1px
 solid gray;"/>
 <br />
    </ItemTemplate>
    </asp:DataList>
</table>
    <asp:SqlDataSource ID="sqldatasource1" runat="server"
     ConnectionString="<%$Connectionstrings:prassidhiConnectionString  %>"
     SelectCommand="SELECT [item_code], [item_name],[item_desc],[picture_file] FROM [item] ">
     </asp:SqlDataSource>
     <br />
    </div
>


Can anyone guide?
Posted
v2

what is the value picture_file contains?

It should be saved like ~/images/file.jpg not the physical path
 
Share this answer
 
Comments
S.Rajendran from Coimbatore 20-Sep-13 7:42am    
I want to retrieve images from rows of a table. Different rows will have diffrent images.
Madhu Nair 20-Sep-13 8:42am    
can you just post the data of one row what picture_file column contains?
I would suggest you to follow this link step by step.

Hope this will help you.
http://www.aspdotnetcodes.com/Insert_Images_Database.aspx[^]
 
Share this answer
 
Hi...
See this one, using datalist and mysql for displaying images.
In aspx:
XML
<asp:DataList ID="DataList1" runat="server" Height="82px"
        ItemStyle-HorizontalAlign="Center" RepeatColumns="3" Width="180px" EnableViewState="true">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
        <ItemTemplate>
        <asp:Image ID="img1" ImageUrl='<%# Bind("Name", "~/Images/{0}") %>' Width="250" Height="180" runat="server" />
        <asp:HyperLink ID="HyperLink1" Text='<%# Bind("Name") %>' NavigateUrl='<%# Bind("Name", "~/Images/{0}") %>' runat="server"/>
            </ItemTemplate>
    </asp:DataList>
<asp:button id="btnpv" text="previous" runat="server" style="font-weight: 700" visible="true" width="66px" onclick="btnpv_Click" xmlns:asp="#unknown" />
<asp:button id="btnx" text="Next" runat="server" style="font-weight: 700" visible="true" width="52px" onclick="btnx_Click" xmlns:asp="#unknown" />

In aspx.cs:
//in page_load only
C#
DirectoryInfo dir = new DirectoryInfo(MapPath("Images"));
            FileInfo[] files = dir.GetFiles();
            ArrayList listitems = new ArrayList();
            foreach (FileInfo info in files)
            {
                if (info.Extension == ".jpg" || info.Extension == ".jpeg" || info.Extension == ".gif" || info.Extension == ".png")
                {
                    listitems.Add(info);
                }
            }

            // bind images on conditional
            adsource = new PagedDataSource();
            adsource.DataSource = listitems;
            adsource.PageSize = 3;
            adsource.AllowPaging = true;
            adsource.CurrentPageIndex = pos;
            btnx.Visible = true;
            //btnx.Enabled = !adsource.IsFirstPage;
            btnpv.Visible = true;
            btnpv.Enabled = !adsource.IsFirstPage;
            DataList1.DataSource = adsource;
            DataList1.DataBind();

C#
protected void btnx_Click(object sender, EventArgs e)
        {
            pos = (int)this.ViewState["vs"];
            pos += 1;
            this.ViewState["vs"] = pos;
            Getimg();
        }

        protected void btnpv_Click(object sender, EventArgs e)
        {
            pos = (int)this.ViewState["vs"];
            pos -= 1;
            this.ViewState["vs"] = pos;
            Getimg();
        }

Thank u.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900