I have a VisualWebPart with a AspTemplateField that should bind a field but it doesn't

The code is the following:

 ID="GridView1" runat="server"
        <asp:BoundField HeaderText="MyType" DataField="MyType" SortExpression="MyType"/>
         <asp:TemplateField  HeaderText="MyType" SortExpression="MyType">
                <asp:Image id="icon" runat="server" ImageUrl='/_layouts/15/MyProject/images/icons/<%# Bind("MyType") %>' />
                <asp:Label ID="tstlbl" runat="server" Text='/_layouts/15/MyProject/images/icons/<%# Bind("MyType") %>' />



Binding is made in c# BehindCode. What I get is: -BoundField prints MyType correctly -asp:Image doesn't print the icon out -asp:Label prints a string without any translation :

/_layouts/15/MyProject/images/icons/<%# Bind("MyType") %>

so Bind inside <%# %> is not evaluated.

Could you tell me why?

2 Answers 2


This is the code from my project

<asp:DataList ID="dlPaging_Top" runat="server" RepeatDirection="Horizontal" OnItemCommand="dlPaging_ItemCommand"
                                <asp:LinkButton ID="lnkbtnPaging" runat="server" CommandArgument='<%# Eval("PageIndex") %>'
                                    CommandName="Paging" Text='<%# Eval("PageText") %>'></asp:LinkButton>

so try '<%# Eval("PageText") %>' and let me know if you have any questions.

  • Thanks but with Eval or Bind the output is the same
    – Gyonder
    Jun 5, 2015 at 10:35

You should try as follow. It will work.

ID="GridView1" runat="server"
     <asp:ImageField DataImageUrlFormatString="~/_layouts/15/MyProject/images/icons/{0}" DataImageUrlField="MyType"></asp:ImageField>    

Hope it will solve your issue.

  • Unfortunately I need to use asp.net components and not html
    – Gyonder
    Jun 5, 2015 at 10:36
  • if you want to use only asp.net components then you need to use asp:ImageField. See my updated answer Jun 5, 2015 at 10:46
  • Is you issue resolved? Jun 5, 2015 at 11:04
  • Actually, it's not. Because my final intent is that have an image button. Following your advice I tried with ButtonField but it doesn't have DataImageUrlFormatString so I cannot do as you suggest. At the moment I've passed all path into MyType. This way Bind works. Anyway, if you have another piece of advice I'm all ears
    – Gyonder
    Jun 5, 2015 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.