C# – ASP.NET- Gridview not display image

asp.netcgridviewsql server

<form id="form1" runat="server">
<div>

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="bookname"  Height="504px" 
        Width="289px">
        <Columns>
            <asp:TemplateField HeaderText="image">
                <ItemTemplate>
                    <asp:Image ID="Image1" runat="server" 
                        ImageUrl='<%# String.Format("~/path/to/image/" + Eval("image")) %>' />
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("image") %>'></asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="bookname" HeaderText="bookname" ReadOnly="True" 
                SortExpression="bookname" />
            <asp:BoundField DataField="price" HeaderText="price" SortExpression="price" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        SelectCommand="SELECT [image], [bookname], [price] FROM [books]">
    </asp:SqlDataSource>

My Image field is saved in (SQL server 2005)…and image inserted in database through file upload button …
and now i want to show data in gridview but not display image field and other field shown in gridview very well becauese other fields are text format.

Best Answer

<asp:Image ID="Image1" runat="server" ImageUrl='<%# String.Format("~/path/to/image/{0}" , Eval("image")) %>' />   

Your Problem was that string.Format accepts arguments and you were using a concat operation. Here i have used {0} - stands for argument at/for index 0. Similarly for multiple arguments you can use string.Format("{0} {1} {2}",var1,var2,var3).

Also above i am assuming {0} will be replaced by file name with extension , like abc.png.

<form id="form1" runat="server">
    <div>
       <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="bookname"  Height="504px" 
            Width="289px">
            <Columns>
                <asp:TemplateField HeaderText="image">
                    <ItemTemplate>
                        <asp:Image ID="Image1" runat="server" 
                            ImageUrl='<%# String.Format("~/path/to/image/{0}" , Eval("image")) %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("image") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="bookname" HeaderText="bookname" ReadOnly="True" 
                    SortExpression="bookname" />
                <asp:BoundField DataField="price" HeaderText="price" SortExpression="price" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            SelectCommand="SELECT [image], [bookname], [price] FROM [books]">
        </asp:SqlDataSource>