0

I'm using a code-behind function (called TestFx) in my binding expression. I'm passing a string and the function accepts a string but I still get a runtime error saying invalid args.

But if I change the method to accept an object and inspect the value, "it's a string!" Can someone please explain?

-rod

   ProductDescription:
                <asp:Label ID="ProductDescriptionLabel" runat="server" 
                    Text='<%# TestFx(Eval("ProductDescription")) %>' />
                <br />

2 Answers 2

1

Another option is to handle repeater control ItemDataBound event. It's more suitable if ItemTemplate elements require complex decoration

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

Comments

0

The return type of Eval is object. As you've noticed, you can either change the signature of your method to accept an object, or you can typecast the result of Eval("ProductDescription") to a string:

<asp:Label ID="ProductDescriptionLabel" runat="server" 
                    Text='<%# TestFx(Eval("ProductDescription").ToString()) %>' />

1 Comment

or if you know for a fact the item will be a string you can just cast it instead of calling ToString

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.