Question

I have a GridView with a template column. In it I have a hyperlink control and I set it's visibility and Navigate URL dinamically using Eval. It all works fine but now I have to add a tooltip to the control, and I need to trim the space and comma at the end of the text.

I'm doing this:

ToolTip='<%# Eval("CombinedAccessions").ToString().TrimEnd(',', ' ') %>'

This works if coded on code behind, but fails when coded on the aspx page. But If I use just TrimEnd(), that function call works fine. What am I doing wrong?

Was it helpful?

Solution

The problem is that the ' sign is breaking you attribute value of ToolTip. You can change the opening and closing sign to " but then it will be broken by the other " you have inside. The solution is to call a method in code behind:

protected string FormatCombinedAccessions(string value)
{
   return value.TrimEnd(',', ' ');
}

And in aspx:

ToolTip='<%# FormatCombinedAccessions((Convert.ToString(Eval("CombinedAccessions"))) %>'

I changed the ToString use to avoid null value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top