linq/ help on conditional vb statement

Hi
I have the following statement and would like to make it conditional.

How do I write this into the statement ?

So instead of this:
<td><a href="/courses/<%# Eval("url") %>.aspx" >info</a></td>

Its something like??

If .category = "camps"
    Dim sFormat As string = "<a href="/courses/camps_{0}.aspx" >info</a>"
    Return.String.Format = (sFormat, .url)

Else
   Dim sFormat As string = "<a href="/courses/{0}.aspx" >info</a>"
   Return.String.Format = (sFormat, .url)

EndIf

<td>????</>

Thanks
Tania
Dim xd As New XDocument
          xd = XDocument.Load (Server.MapPath("/App_Data/courseList.xml"))
					
	Dim query = From q In xd...<product> _
		Where Not (q.parent.@code = "ds" or q.parent.@code = "other") _
		Order By q.@title _
		Select New With { _
				.category = q.parent.@title, _
				.summary = q.<shortSummary>.Value, _
				.url = q.<courseUrl>.Value, _
				.title = q.@title, _
				.duration = q.<duration>.Value, _ 
				.dates = (From d In q.<dates>.<date> _
							 Select New With { _
									.date = d.Value}) _	
											 } 			 
						e.Result = query	
						
	End Sub

Open in new window

Tania_FarmerAsked:
Who is Participating?
 
Éric MoreauSenior .Net ConsultantCommented:
have you tried replacing:
.url = q.<courseUrl>.Value, _

with:
.url = If( .category = "camps", string.format("<a href="/courses/camps_{0}.aspx" >info</a>", q.<courseUrl>.Value), string.format("<a href="/courses/{0}.aspx" >info</a>", q.<courseUrl>.Value))
0
 
Éric MoreauSenior .Net ConsultantCommented:
have you tried this:
If( .category = "camps", string.format("<a href="/courses/camps_{0}.aspx" >info</a>", .url), string.format("<a href="/courses/{0}.aspx" >info</a>", .url))

Open in new window

0
 
Tania_FarmerAuthor Commented:
Hi,
How do I format the statement?

<td>

<%# Eval("url"), If( .category = "camps", string.format("<a href="/courses/camps_{0}.aspx" >info</a>", .url), string.format("<a href="/courses/{0}.aspx" >info</a>", .url))%>


</td>

Is it possible to write it above in the Protected Sub listsource_Selecting section?
Protected Sub listsource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles listsource.Selecting
		 
     Dim xd As New XDocument
       xd = XDocument.Load (Server.MapPath("/App_Data/courseList.xml"))
                                        
       Dim query = From q In xd...<product> _
          Where Not (q.parent.@code = "ds" or q.parent.@code = "other") _
           Order By q.@title _
           Select New With { _
                                .category = q.parent.@title, _
                                .summary = q.<shortSummary>.Value, _
                                .url = q.<courseUrl>.Value, _
                                .title = q.@title, _
                                .duration = q.<duration>.Value, _ 
                                .dates = (From d In q.<dates>.<date> _
                                                     Select New With { _
                                                                        .date = d.Value}) _     
                                                                                         }                       
                                                e.Result = query        
                                                
        End Sub

Open in new window

0
 
Tania_FarmerAuthor Commented:
Hi,
That's exactly what I was looking for.

Thanks
T
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.