views:

69

answers:

2

I have a usercontrol in an asp web forms application that I am working on in C#.

I am binding to a repeater and outputting a field of information, named "Text", using the following syntax:

<%# DataBinder.Eval(Container.DataItem, "Text") %>

I am looking for a method that will allow my to search for a keyword within the string that is returned from above, and replace that string with a hyperlink such as

<a href="www.anysite.com/keyword">keyword</a>.

I'm not very familiar with user controls and getting data back in this manner so I am looking for advice on how this might be best handled.

Thanks!

A: 

You should be able to use the OnItemDataBound event to check the value before you display it to the user.

Create a new method in your codebehind and set the OnItemDataBound="newmethod" so everytime an item gets bound it will call the method. Then in the method you check the data and if it needs to be change to a hyperlink you can change it at that time.

Dan H
+4  A: 

Hook into the Repeater's OnItemDataBound event.

The example on the linked documentation page does almost exactly what you want to do - it finds a label control in the item and updates the text. You should be able to modify it from there to do a string find/replace.

womp
Thanks for the link Womp. That was excatly what I was looking for!
Richard West