Display image in grid view saved on the server
I have a grid view in which I want to show images. I am storing images on the server and path is stored in the databse. The path is "C:\Inetpub\wwwroot\BISv01\Images\Upload\Chirag.jpg" When I fetch records from database, all columns are fetched but image is not visible in gridview. Below is the code for my gridview
<asp:GridView ID="grdCurrency" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333"
GridLines="None" onrowcommand="grdCurrency_RowCommand">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="CurrencyID" HeaderText="ID" />
<asp:BoundField DataField="CurrencyName" HeaderText="Currency" />
<%--<asp:BoundField DataField="" HeaderText="Logo" />--%>
<asp:ImageField DataImageUrlField="CurrencyLogo" HeaderText="Currency Logo">
</asp:ImageField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnEdit" runat="server" Text="Edit"
CommandArgument='<%# Eval("CurrencyID") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
//Below is the code to fill the gridview.
DataTable dtCurrency = null;
dtCurrency=oCurrency.GetAllCurrency();
if (dtCurrency != null && dtCurrency.Rows.Count > 0)
{
grdCurrency.DataSource = dtCurrency;
grdCurrency.DataBind();
grdCurrency.Col开发者_StackOverflowumns[0].Visible = false;
lblGrdCount.Text = "Total ["+grdCurrency.Rows.Count+"] records found";
}
Please help me to point out my mistake.
First of all don't store the complete image path. You have to store the image path like..'~/Images/Upload/Chirag.jpg'
in the DB.
Then this will allow you to show the image. e.g.
<asp:TemplateField>
<ItemTemplate>
<asp:Image ImageUrl='<%#Eval("CurrencyLogo") %>' ID="Image1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
精彩评论