Click here to Skip to main content
16,020,305 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi i tried to display image from sql table to gridview but its not displaying this s my code to bind gridview with sql table records..
protected void Page_Load(object sender, EventArgs e)
   {
       SqlCommand cmd = new SqlCommand("Select * from tblImage",con);
       try
       {
           cmd.Connection.Open();

           SqlDataReader reader = cmd.ExecuteReader();
           gvwExample.DataSource = reader;
           gvwExample.DataBind();
           cmd.Connection.Close();
           cmd.Connection.Dispose();

       }
       catch (Exception ex)
       {
           lblStatus.Text = ex.Message;
       }

   }


and this is the design code
<pre><asp:GridView ID="gvwExample" runat="server" AutoGenerateColumns="false">
    
    <columns>
    <asp:BoundField DataField="iName" HeaderText="Name" />
    <asp:BoundField DataField="iAddress" HeaderText="Address" />
    <asp:TemplateField HeaderText="Photo">
                  <ItemTemplate>
                    <asp:Image ID="Image1" ImageUrl='<%#(Eval("iImage"))%>' runat="server" Width="200" Height="200"/>
                  </ItemTemplate>
                </asp:TemplateField>
    </columns>
   
    
    </asp:GridView>



please suggest..thanks and regards..
Posted

 
Share this answer
 
v2
Comments
ythisbug 9-May-12 5:43am    
thanks
Prasad_Kulkarni 9-May-12 7:32am    
Glad it helps!
Thank you for 'Accepting Solution'
XML
<asp:Repeater ID="repview" runat="server" >
                        <ItemTemplate>
                            <td class="bdr_top para_cbox bdr_lft">
                                <%#Eval("name")%>
                            </td>
                            <td align="center" class="bdr_lft bdr_top para_cbox ">
                                <img src="<%#Eval("iImage")%>" alt="" border="0" height="50" width="50" />
                            </td>
                            
                           
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
 
Share this answer
 
Comments
Manzoorali29 17-Jul-12 8:20am    
sir i trid the above code for mysql database it work fine for url but not for the image field in mysql. my field datatype is longblob. plz help thanks

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