OneSmartGuy
OneSmartGuy

Reputation: 2939

Unable to bind in asp.net grid Template Column

I am having trouble accessing the data field. I receive the error: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

I can get the value but using <%# getOpenJobs((string)Eval("ParentPart")) %> but I need to use it in the if to display a certian picture if it passes the condition. Is there a better way to do this or am i just missing something simple?

               <telerik:GridTemplateColumn UniqueName="hasOpenJobs" HeaderText="">
                <ItemTemplate>
                        <% if (getOpenJobs((string)Eval("ParentPart")) > 1)
                           { %>
                            <img src="../images/job-icon.gif" alt="Open Jobs" />
                         <%} %>
                </ItemTemplate>
            </telerik:GridTemplateColumn>

Upvotes: 1

Views: 1712

Answers (1)

Andrew Corkery
Andrew Corkery

Reputation: 1024

In these cases, I usually create a method in the code-behind to send back the final generated HTML. E.g.

<ItemTemplate>
<%# GetJobImageHtml((string)Eval("ParentPart")) %>
</ItemTemplate>

Then do whatever logic you need in the GetJobImageHtml() method and return a HTML string.

Upvotes: 3

Related Questions