2014年7月13日 星期日

[RESOLVED] Display Photo in Item Template


I'm use to setting up a photo in a List View or Grid View just using the wizards in Visual Studio. I was given a simple example of an Item template, which works well for what I'm doing, but I'm not sure how to display a photo with it. I have a folder in
my project with the photos in it. I store the path to the photos in my sql database. How do I display the photos with the other fields in my Item template? Here is the code I have so far:




<%# Eval("SodaName")%>
Price Range:<%# Eval("PriceRange")%>
<%# Eval("StoreName") %>
.....and so on.



 



Add an Image control and bind its ImageUrl property to the database field that stores the path. 



Use Image Control and bind ImageUrl Property.


If you saved filename only to SodaName, bind ImageUrl like this :



If you store the path like "~/images/filename.jpg" or "images/filename.jpg" use like this



Dont store the path like "c:\images\filename.jpg", store virtual path (url) instead.







You can have the two options like bellow Hope it helps for you

option 1:



  
        ImageUrl='<%# Eval("Path") %>' />





option 2:


     DataImageUrlFormatString="~/images/{0}.jpg">


For refer


http://www.aspdotnet-suresh.com/2011/01/how-to-insert-images-into-database-and.html


http://msdn.microsoft.com/en-us/library/aa479350.aspx






                                                       

                                                           

                                                               
                                                                    Width="70px" Height="50px" />

                                                          

                                                           

                                                       


                                                   


in aspx.cs page


 public string GetImageURL(string url)

    {

      

        string taxid = url;

   



        taxid = "~/UploadedDocument/VehiclePhoto/" + url+".jpg" ;



        return taxid;

    }


沒有留言:

張貼留言