Question : ASP.NET -  How to use an IF ELSE within a bound object (Datalist)

I am trying to have a bound data list that gets a value from a query string and then writes code according to this.   Essentially have an IF ELSF IF within the datalist that writes a different bit of code according to whether the URL value = and ID value in the sql/datalist.

I'm getting this error, which I believe says that I can't do this within a databound control.

"Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control."

i want this eg.

url = 3

1 = ahref="1">
2 = ahref="2">
3 = ahref="">
4 = ahref="4">
1:
2:
3:
4:
5:
6:
7:
<% If Request.QueryString("brand") = "" Then %> <a class="nav" href="<%# Request.Url %>&brand=<%# Eval("id") %>"><asp:Label ID="Label1" runat="server" Text='<%# Eval("brandName") %>' /></a> 
                 
                 <% ElseIf Request.QueryString("brand") = Eval("id") Then%> <a class="nav" href="<%# Request.Url %>"><asp:Label ID="Label3" runat="server" Text='<%# Eval("brandName") %>' /></a> 
                 
                 <% Else: %> <a class="nav" href="<%# Request.Url %>"><asp:Label ID="Label2" runat="server" Text='<%# Eval("brandName") %>' /></a> 
                 
                 <% End If%>

Answer : ASP.NET -  How to use an IF ELSE within a bound object (Datalist)

you should really be doing this in the codebehind using the asp:Hyperlink

eg.

If Request.QueryString("brand") = 3 Then lnkItem3.NavigateUrl = ""

for fear of insulting you, is there a particular reason why you havent?
Random Solutions  
 
programming4us programming4us