views:

142

answers:

2

Here's my GridView HTML:

<asp:GridView ID="gvPortfolioImages" runat="server" AutoGenerateColumns="False" DataSourceID="ldsPortfolioImages">
    <Columns>          
        <asp:TemplateField HeaderText="Image" SortExpression="Filename">
            <ItemTemplate>
                <img src='<%# Portfolio.GetImageURL(Eval("Thumbnail").ToString()) %>' alt='<%# Eval("Thumbnail") %>' />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

I'm get the following error where I'm trying to call Portfolio.GetImageURL():

The name 'Portfolio' does not exist in the current context

I've seen functions called like this before, but it doesn't seem to be working for me. Can anyone tell me what the problem is?

A: 

Assuming that Portfolio is a valid object, have you provided a reference to its namespace via the using statement? Also check to make sure GetImageURL() a static function. You may want to simply place a mock protected static string GetImageURL() function in the code-behind of your GridView. You might be able to determine is root cause through trial and error.

Ben Griswold
+1  A: 

In your aspx page you need to include the namespace so the compiler knows about your Portfolio object which I am assuming is a static class with a static function (if not you will need to instantiate your Portfolio object before using it). Here is the snippet you will need to add after the <@ Page at the top of your aspx file. Replace the string with the correct namespace of course.

<%@ Import Namespace="YourApps.Namespace.Where.PorfolioIs" %>

The error is occuring because it has no idea what Portfolio is. It's just like if you tried to reference it in your codebehind (.cs file) without a using statement including the namespace where you Portfolio class exists.

Kelsey
Thanks for this, I was forgetting to import the correct namespace.
Steven