Image can't be seen

Last post 05-17-2008 6:28 PM by Aha. 6 replies.

Sort Posts:

  • Image can't be seen

    05-14-2008, 8:11 PM
    • Loading...
    • Aha
    • Joined on 04-22-2008, 4:40 AM
    • Posts 30

    Hi

    I have a database that has 2 fields (columns) to store JPG images. In my form I have a DropDownList to input key words for searching and a DetailView to display record one at a time. In my database table I put the image file names in the Image1 & Image2 fields respectively. In order to display images for each record, I add the following codes, but the images can't be seen. Am I missing anything?

    <asp:DetailsView ID=.........>

          ................

    </asp:DetailsView>

    <asp:image ImageUrl='<%# Eval("Image1", "~/drugimages/{0}") %>' runat="server" id="Image1"
                            style="float:left; border: none; margin-right: 10px;" />
    <asp:image ImageUrl='<%# Eval("Image2", "~/drugimages/{0}") %>' runat="server" id="Image2"
                            style="float:left; border: none; margin-right: 10px;" /> 

  • Re: Image can't be seen

    05-14-2008, 8:32 PM
    • Loading...
    • mbanavige
    • Joined on 11-06-2003, 8:29 AM
    • New England, USA
    • Posts 7,424
    • Moderator
      TrustedFriends-MVPs

    when your page renders in the browser, do a view source to see what has been set for the src attribute of the img tag.

    Mike Banavige
    ~~~~~~~~~~~~
    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Image can't be seen

    05-15-2008, 1:13 AM

    Hi

    check data is comming properly from database.

    check for proper folder name.

    Just post your code here so we can check it.


    Suyog
    Please click on “Mark as Answer”button if it helps you.
  • Re: Image can't be seen

    05-15-2008, 2:08 AM
    • Loading...
    • Aha
    • Joined on 04-22-2008, 4:40 AM
    • Posts 30

    Hi Mike,

    I do what you said and get the following:

    <img id="ctl00_ContentPlaceHolder1_TabContainer1_TabPanel2_Image1" src="" style="border-width:0px;float:left; border: none; margin-right: 10px;" />
    <img id="ctl00_ContentPlaceHolder1_TabContainer1_TabPanel2_Image2" src="" style="border-width:0px;float:left; border: none; margin-right: 10px;" />

    It seems that my src="" is empty. Which part should I fix? Can we displat an image in a cell of DetailView? Thank you.

  • Re: Image can't be seen

    05-15-2008, 3:55 AM
    • Loading...
    • Aha
    • Joined on 04-22-2008, 4:40 AM
    • Posts 30

    Hi, 

    Initially I intend to display my images in the cells of DetailView, as you can see the 2 lines with italic letters. Of course, it fails to show anything. Then I add <asp:image ImageURL...........> (you can see in Italic), it still doesn't work. Does it connect to my AccessDataSource2 when I put them in this way?

    <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" title="Information Web" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="1" Height="1280px">
            <ajaxToolkit:TabPanel ID="TabPanel1" runat="server" HeaderText="Home">
            </ajaxToolkit:TabPanel>
            <ajaxToolkit:TabPanel ID="TabPanel2" runat="server" HeaderText="Search">
                <ContentTemplate>
                    <asp:Label ID="Label1" runat="server" Text="Please select code:" Width="130px"></asp:Label>
                    <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="AccessDataSource1"
                        DataTextField="Code" DataValueField="ID" AutoPostBack="True">
                    </asp:DropDownList>
                    <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/drugdata.mdb"
                        SelectCommand="SELECT [Code], [ID] FROM [tbDrug]">
                    </asp:AccessDataSource> <hr />
                    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="AccessDataSource2" Height="60px" Width="965px" FieldHeaderStyle-Width="70px">
                        <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
                        <RowStyle BackColor="#DEDFDE" ForeColor="Black" HorizontalAlign="Left" VerticalAlign="Top"/>
                        <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
                        <Fields>
                            <asp:BoundField DataField="Code" HeaderText="Code" SortExpression="Code" />
                            <asp:BoundField DataField="Category" HeaderText="Category" SortExpression="Category" />
                            <asp:BoundField DataField="OriginName" HeaderText="OriginName" SortExpression="OriginName" />
                            <asp:BoundField DataField="TradeName" HeaderText="TradeName" SortExpression="TradeName" />
                            <asp:BoundField DataField="Form" HeaderText="Form" SortExpression="Form" />
                            <asp:BoundField DataField="Packing" HeaderText="Packing" SortExpression="Packing" />
                            <asp:BoundField DataField="Contents" HeaderText="Contents" SortExpression="Contents" />
                            <asp:BoundField DataField="Dosage" HeaderText="Dosage" SortExpression="Dosage" />
                            <asp:BoundField DataField="Indication" HeaderText="Indication" SortExpression="Indication" />
                            <asp:BoundField DataField="Contraindication" HeaderText="Contraindication" SortExpression="Contraindication" />
                            <asp:BoundField DataField="Precaution" HeaderText="Precaution" SortExpression="Precaution" />
                            <asp:BoundField DataField="Warning" HeaderText="Warning" SortExpression="Warning" />
                            <asp:BoundField DataField="SideEffect" HeaderText="SideEffect" SortExpression="SideEffect" />
                            <asp:BoundField DataField="PregCategory" HeaderText="PregCategory" SortExpression="PregCategory" />
                            <asp:BoundField DataField="Shape" HeaderText="Shape" SortExpression="Shape" />
                            <asp:BoundField DataField="Company" HeaderText="Company" SortExpression="Company" />
                            <asp:BoundField DataField="Image1" HeaderText="Image1" SortExpression="Image1" />
                            <asp:BoundField DataField="Image2" HeaderText="Image2" SortExpression="Image2" />
                             
                        </Fields>
                        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
                        <EditRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
                    </asp:DetailsView>                

                    <asp:image ImageUrl='<%# Eval("Image1", "~/drugimages/{0}") %>' runat="server" id="Image1"
                            style="float:left; border: none; margin-right: 10px;" />
                    <asp:image ImageUrl='<%# Eval("Image2", "~/drugimages/{0}") %>' runat="server" id="Image2"
                            style="float:left; border: none; margin-right: 10px;" /> 
                   
                    <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/drugdata.mdb"
                        SelectCommand="SELECT tbCategory.*, tbDrug.*, tbForm.* FROM (tbCategory INNER JOIN tbDrug ON tbCategory.ID =  tbDrug.CategoryID) INNER JOIN tbForm ON tbDrug.FormID = tbForm.ID WHERE tbDrug.ID =?">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="DropDownList1" DefaultValue="1" Name="ID" PropertyName="SelectedValue" />
                        </SelectParameters>
                    </asp:AccessDataSource>
                </ContentTemplate>
            </ajaxToolkit:TabPanel>
         </ajaxToolkit:TabContainer>
    </asp:Content>

  • Re: Image can't be seen

    05-15-2008, 5:05 AM
    • Loading...
    • Deleo
    • Joined on 11-04-2007, 10:33 AM
    • Posts 140

    Try to call the databind() method of the images explicitly. When you call databind(), all databindexpressions will be evaluated and your src will be set :)

    databind either in OnLoad or OnInit :)

     

  • Re: Image can't be seen

    05-17-2008, 6:28 PM
    • Loading...
    • Aha
    • Joined on 04-22-2008, 4:40 AM
    • Posts 30

    Although I don't really understand what you suggest me to do, thanks a lot. I search through this forum and finally solve my problem. I do this by placing a <asp:TemplateField> in my DetailsView as follow:

    <asp:DetailsView runat="server">

       <Fields>

          <asp:TemplateField>

             <HeadTemplate>Picture</HeaderTemplate>

             <ItemTemplate>

                <asp:Image runat="server" ImageUrl''<%# Eval ("MyImageColumn")%>' />

             </ItemTemplate>

          </asp:TemplateField>  

    </Fields> 

    </asp:DetailsView>

    I post it here in the hope that those whose are new in ASP.NET can get some help.

Page 1 of 1 (7 items)