views:

239

answers:

2

Hey everyone,

I've got a repeater and it is bound to a dictionary . Although I can access the HyperLink, I can't render one. I have this code:

<%# DataBinder.Eval((System.Collections.Generic.KeyValuePair<string, HyperLink>)Container.DataItem, "Value.NavigateUrl") %>

The Value.NavigateUrl was a test to see if I could access that property, and I can. The output is the URL the hyperlink to link to. I also tried 'Text', which worked. This means that it's recognized as a HyperLink, and can be accessed as one, but I would like to render it as one. How can I do this?

Thanks for any help

A: 

Why don't you try to put it on a LITERAL control in the repeater... this will work.

MRFerocius
I tried placing it within a literal control tag and got a `'System.Web.UI.WebControls.Literal' does not allow child controls.` error.
Skoder
+1  A: 

There may be a more elegant solution, but this is what I came up with, a protected function that calls the RenderControl method of the Hyperlink control.

In your code behind:

using System.IO;
...

protected string RenderLink(object h)
{
  StringWriter sw = new StringWriter();
  HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);
  HyperLink link = (HyperLink)h;
  link.RenderControl(htmlWriter);
  return sw.ToString();
}

Then just call that function from your Repeater:

<%# RenderLink(DataBinder.Eval((System.Collections.Generic.KeyValuePair<string, HyperLink>)Container.DataItem, "Value")) %>
wsanville
Thanks, this worked!
Skoder