item template not expanded inside a repeater

A

Andy Fish

Hi,

In a repeater control I had something like this:

<a id="lnk_Lookup" href='lookup.aspx?userid=<%#DataBinder.Eval(Container,
"DataItem.UserId")%>'>go</a>

This works fine and the href is generated correctly. However, I also want to
process the control in the codebehind file, so I added a "runat=server"
attribute. Now the URL is not substituted by the databinder so it remains
the literal string as seen in the source for the page.

I have also tried changing it to an <asp:hyperlink> but still the same
result.

Any ideas what is happening here?

TIA

Andy
 
S

Scott Allen

Hi Andy:

It doesn't look like the ASPX parser picks up the databinding syntax
if it is embedded inside of the attribute.

In other words:

<a id="A1" runat="server" href='<%#
DataBinder.Eval(Container.DataItem, "Foo") %>'>GO</a>

<a id="A2" runat="server" href='foo.aspx?foo=<%#
DataBinder.Eval(Container.DataItem, "Foo") %>'>GO</a>

A1 appears to generate the right code - but A2 does not. You can look
at the generated .cs or .vb in the temporary ASP.NET files directory.

What you might want to do, since you need to add runat="server"
anyway, is to hook the ItemDataBound event of your repeater, use
FindControl to get a reference to the hyperlink, and set the href in
the code behind. It's very similar to what ASP.NET would code gen for
you - but you'll be able to do it correctly ;)
 
A

Andy Fish

Ah, thanks. At least it wasn't me going mad.

I notice that (as you'd expect) this works too:

<a id="A3" runat="server" href='<%#"foo.aspx?foo=" +
DataBinder.Eval(Container.DataItem, "Foo") %>'>GO</a>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top