Search code examples
asp.netgridviewstringreplacedatabound

How can I replace characters from a databound object?


I have this:

<img id="imgField" alt="" runat="server" src='<%# string.Format("images/{0}.jpg", DataBinder.Eval(Container.DataItem,"Name")) %>' />

and it's rendering %20's from the spaces in the databound Name. So I need to replace all of the "%20's" with ""

I tried

<img id="imgField" alt="" runat="server" src='<%# string.Format("images/{0}.jpg", DataBinder.Eval(Container.DataItem,"Name")).Replace("%20","") %>' />

and that didn't work... Anyone know?

Thanks,
Matt


Solution

  • The %20 values are probably a result of the control parsing the attribute. If you want to eliminate spaces try .Replace(" ", "")