Why is the image not displayed in grid mode?

<asp:TemplateField HeaderText="Image">
    <ItemTemplate>
        <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("imagepath") %>' Height="100px"
                   Width="100px" />
    </ItemTemplate>
</asp:TemplateField>

      

The path, which is a binding, is C:/inetpub/wwwroot/Image/FolderName/abc.jpg

from the table, but is not displayed. The image is in the same folder and doesn't even give any exceptions.

+3


source to share


3 answers


<img src='<%# Eval("imagepath").ToString() %>' Width="100px" Height="100">

      



maybe you can do something like this?

+2


source


these codes are the source of the gridview

<asp:GridView ID="grv" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1">
             <Columns>
                <asp:BoundField DataField="PicID" HeaderText="PicID" ReadOnly="True" InsertVisible="False" SortExpression="PicID"></asp:BoundField>
                <asp:BoundField DataField="PicURL" HeaderText="PicURL" SortExpression="PicURL"></asp:BoundField>
                <asp:BoundField DataField="PicName" HeaderText="PicName" SortExpression="PicName"></asp:BoundField>
                <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date"></asp:BoundField>
            </Columns>
            <Columns>
                <asp:BoundField HeaderText="Picutre ID" DataField="PicID"></asp:BoundField>
                <asp:BoundField HeaderText="Title" DataField="PicName"></asp:BoundField>
                <asp:BoundField HeaderText="Date Added" DataField="Date" DataFormatString="{0:d}"></asp:BoundField>
                <asp:ImageField DataImageUrlField="PicURL" ></asp:ImageField>
            </Columns>
        </asp:GridView>

      

these codes are sql table



CREATE TABLE PicTable
(
PicID int identity(1,1),
PicURL nvarchar(50),
PicName nvarchar(50),
Date datetime
);


select * from PicTable
insert PicTable values('~/Uploads/4626411630_ASO%20(1).jpg','Water Lilies','2015.02.27')

      

you can add values ​​like this. you should have a folder in your solution browser. For example, my folder name is Uploads. I hope these codes are helpful for you or another developer.

0


source


Instead you can directly convert the BLOB or Binary in <asp:Image> tag and click on the Button Tag, it will take you to the IndexChangedFunction and you can do further operations with the grid:

    <asp:GridView ID="Gvid" runat="server" Width="100%" AutoGenerateColumns="false" OnSelectedIndexChanged="Gvid_SelectedIndexChanged" >
            <Columns>
<asp:TemplateField HeaderText="IMAGE" Visible="false">
<ItemTemplate>
<asp:Image runat ="server"  ImageUrl='<%# "data:image/jpg;base64," + Convert.ToBase64String((byte[])Eval("IMAGE")) %>' ID="Image"  />
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField DataTextField ="MODEL" CommandName="select" HeaderText ="MODEL" />
</Columns> 
</asp:GridView>

      

0


source







All Articles