Click here to Skip to main content
15,905,068 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi,

Can anyone know?

why image is not binding in gridview?

source:
XML
<asp:TemplateField HeaderText="Company Logo">
                    <ItemTemplate>
                   <asp:Image ID="clogo" runat="server" ImageUrl='<%#Bind("clogo") %>' />
                    </ItemTemplate>
                    </asp:TemplateField>

.cs code:
C#
public void load_grid()
   {

       SqlConnection cn = new SqlConnection(ConfigurationManager.AppSettings["constring"].ToString());
       SqlCommand cmd = new SqlCommand("select * from tbl_company1 where cstatus='Active'", cn);
       SqlDataAdapter da = new SqlDataAdapter(cmd);
       DataSet ds = new DataSet();
       da.Fill(ds);
       grdviewcompany.DataSource = ds;
       grdviewcompany.DataBind();
       cn.Close();
   }
Posted
Updated 9-Feb-12 22:51pm
v2
Comments
Herman<T>.Instance 10-Feb-12 5:39am    
don't you bind your ID instead of a db value?
==>ID="clogo" runat="server" ImageUrl='<%#Bind("clogo")
sathiyak 10-Feb-12 5:52am    
give me any other solution if u know...
Herman<T>.Instance 10-Feb-12 7:20am    
set ID=clogo to ID=mylogo and see what happens.
I assume that clogo is a folderpath with filename?

1 solution

Hi,
You cant bind straightly image to gridview. Because image stored byte array format in database. so, we need to convert as human visible format using HttpHandler, then bind to gridview.




Regards,
anbukrish
 
Share this answer
 

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