2

I have a gridview. I want to bind something like:

<asp:TemplateField //stuff>
  <ItemTemplate>
    <asp:Label ID="lblEx" runat="server" text='<%# SomeJavascriptFunction( Eval("BOUND_FIELD_FROM_DB") ) %>' ></asp:Label>
  </ItemTemplate>
</asp:TemplateField>

This exact syntax doesn't appear to be working - it's telling me the function isn't declared (it is). I'm thinking it's looking for SomeJavascriptFunction() in the code-behind. Is there some way to make this work?

I can't seem to find the correct verbiage in my searches - results all seem to be regarding binding a gridview through javascript, which is not exactly correct.

EDIT:

I do have a code-behind version implemented and working - I'd just like to take the processing load off the server.

2 Answers 2

1

Ok, so try with some jQuery magic:

$(document).ready(function () {
        $("[id*=lblEx]").each(function () {
            $(this).text(someJavascriptFunction($(this).text()));
        });
    });
    function someJavascriptFunction(id) {
        return "the final text in the cell";
    }

i've tested this and works.

Greetings,

Sign up to request clarification or add additional context in comments.

2 Comments

Unfortunately not. This just renders SomeJavascriptFunction(<%# Eval("BOUND_FIELD_FROM_DB")%>) to the cell.
Thank you. I'm not at all familiar with JQuery, but this is very helpful.
0

Actually it is looking for a code behind method SomeJavascriptFunction() and the data returned from it will bind to the Label. You can add the corresponding method in code behind:

public string SomeJavascriptFunction(object obj)
{
    return "Some value";
}

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.