Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi,
I am using sql server as a back-end to store name of image as varchar.
I want to retrieve those images and show them into grid view.
I am using Linq to retrieve data.
I have used asp:Image control into column itemtemplate.
But I have no Idea, how to do that.
Should I change table structure? DataSource property wont work I guess
Please help me out..
Thanks
Posted

after binding data in datatable
then
in grid view you can call image like this

<asp:image id="imgPic" runat="server" height="50px" width="50px" imageurl="<%#Eval(" studentphotopath")="" %&gt;"="" xmlns:asp="#unknown">
 
Share this answer
 
Comments
prashantttt 14-Oct-13 6:49am    
here studentphotopath is d name of column....?
Hi,

I am assuming you have saved the image path in database.
Try following code.

in Aspx page.

ASP.NET
<asp:gridview id="grid" runat="server" onrowdatabound="grid_RowDataBound" xmlns:asp="#unknown">
     <columns>
         <asp:templatefield>
             <itemtemplate>
                 <asp:image runat="server" id="img" width="100px" height="100px" />
             </itemtemplate>
         </asp:templatefield>
     </columns>
 </asp:gridview>


in your code behind

C#
protected void grid_RowDataBound(Object sender, GridViewRowEventArgs args)
       {
           if (args.Row.RowType == DataControlRowType.DataRow)
           {
               DataRowView rowView = (DataRowView)args.Row.DataItem;
               Image img = (Image)args.Row.FindControl("img");
               img.ImageUrl = rowView["Images"].ToString();
           }
       }


Note this is faster than using EVAL or bind in your aspx.


Hope this helps.
 
Share this answer
 
v2
Comments
prashantttt 14-Oct-13 7:22am    
hi abhidev
I tried ur solution bt its showing me image column blank.....
any suggestions..?
bitofweb 14-Oct-13 8:08am    
Hi are you setting the image path correctly.

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