Google Answers Logo
View Question
 
Q: Display an Image in a DataGrid using VB.Net ( No Answer,   3 Comments )
Question  
Subject: Display an Image in a DataGrid using VB.Net
Category: Computers > Programming
Asked by: bdwgarth-ga
List Price: $5.00
Posted: 23 Jun 2004 11:27 PDT
Expires: 23 Jul 2004 11:27 PDT
Question ID: 365171
I am developing a web application with Visual Studio.Net using VB.Net
page language. I would like to display an image, approximately 50 x 50
pixels in size, in one of the columns of the datagrid. I have the
filename for the images stored in database.  Currently the filename
appears in the datagrid, but I would like the picture to be displyed
instead. I am looking for the code that would go in the HTML for the
datagird control, and also the VB.net code to get the image and
display it in the datagrid. Thank  you

Clarification of Question by bdwgarth-ga on 30 Jun 2004 09:15 PDT
I have this line of code in my HTML but the images have to be in the
root directory where the aspx page runs inorder for them to be displayed.
<asp:Image Width="90" Height="60" runat="server" ImageUrl= '<%#
DataBinder.Eval(Container.DataItem, "Picture") %>'>

I dont want the files to be in the root directory, so I am looking for
a function in vb.net or some type of string format in html that will
access the path were the images are located on the server.

Perhaphs something like this...

Protected Function GetImageUrl(???) As String
        Dim ImagePath As String
        ImagePath = "http://www.website.com.temp/"
        Return ImagePath
End Function

ImageUrl= '<%# GetImageUrl(DataBinder.Eval(Container.DataItem, "Picture")) %>'

I tryed something like this but it did not work. Error out saying
GetImageUrl not declared as a function.

Any suggestions or methods or code samples in vb.net

Thanks
Answer  
There is no answer at this time.

Comments  
Subject: Re: Display an Image in a DataGrid using VB.Net
From: jangel-ga on 24 Jun 2004 07:08 PDT
 
Insert a placeholder image and use this code for the 'databinding':

DataBinder.Eval(Container.DataItem, "yourDBcolumn")
Subject: Re: Display an Image in a DataGrid using VB.Net
From: bdwgarth-ga on 30 Jun 2004 08:58 PDT
 
This works but...

I have this line of code in my HTML but the images have to be in the
root directory where the aspx page runs.
<asp:Image Width="90" Height="60" runat="server" ImageUrl= '<%#
DataBinder.Eval(Container.DataItem, "Picture") %>'>

I dont want the files to be in the root directory, so I am looking for
a function or some type of string format that will access the path
were the images are located.

Protected Function GetImageUrl(???) As String
        Dim ImagePath As String
        ImagePath = "http://www.website.com.temp/"
        Return ImagePath
End Function

ImageUrl= '<%# GetImageUrl(DataBinder.Eval(Container.DataItem, "Picture")) %>'

I tryed something like this but it did not work. 

Any suggestions
Thanks
Subject: Re: Display an Image in a DataGrid using VB.Net
From: sleepychristoph-ga on 05 Jul 2004 15:15 PDT
 
Use a template column

e.g.

      <asp:TemplateColumn runat="server" HeaderText="Photo">
    <itemtemplate>
        <img runat="server" width="50"  
           visible=TRUE 'Or could be function which evaluates if picture exists   
           src='<%# "YourPathHere" + DataBinder.Eval(Container.DataItem, 
           "YourDBColumn")  %>' />
    </itemtemplate>
       </asp:TemplateColumn>

You can find good examples here :
http://msdn.microsoft.com/msdnmag/issues/02/01/cutting/default.aspx

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy