newbie question on tests and styles

N

Neil

Hi,

I have a datalist of links.

I want the selected link to be a different style / class and prefereably not
a link.

I have created the following code which failed because of the test in line
2 - can anyone advise how I could do this?

Many thanks,

NEIL

<ItemTemplate>

<% If Request.QueryString("CID") <> Eval("ID") Then%>

<asp:HyperLink id="HyperLink1" runat="server" Text='<%# Eval("sName") %>'
NavigateUrl='<%# "default.aspx?CID=" & Eval("ID") %>'
__designer:wfdid="w11"></asp:HyperLink>

<% Else%>

<asp:Label id="Label1" runat="server" Text='<%# "<div class=""black"">" &
Eval("sName") & "</div>" %>' __designer:wfdid="w12"></asp:Label>

<% end if %>

</ItemTemplate>
 
K

Kevin Frey

As far as I know (and I could be wrong), a test such as what you have used
is not permitted in the definition of an item template.

As I understand it, a good part of the reason for this is because you don't
really want your control tree (the controls belonging to a page) to change
its structure dynamically between post-backs.

The alternatives that come to mind are:

1. Simply embed both controls into the Item template, and use an eval
expression to set either the Visible or Enabled properties of each control
to ensure you get the correct one being displayed (obviously each control
will have the inverse setting of the other, so only one is visible).

2. You could write your own control (eg. LabelOrHyperlink) that attempts to
implement the kind of logic you are trying to achive. Although this would be
non-trivial to make a useful control.

Cheers

Kevin
 

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