views:

424

answers:

3

I have to convert some code from classic ASP to ASP.NET

1) How can I best handle syntax as below, where it seems to fail because the code is inside a tag, and also perhaps because the condition is split over several tags.

2) Any tools or guidelines that are good on this kind of code?

3) Classic ADO.

    <li><a<% if "" = myFolder then %> class="selected"<% end if %> href="http://&lt;%= SERVER_NAME %>/"><%= getLocale("Home") %></a></li>
         <% SQL = "SP_TOPNAV  '" & lang & "'"
            Set maNav = conn.execute(SQL)
            do while not maNav.EOF %>
                <li><a<% if maNav(0) = myFolder then %> class="selected"<% end if %> href="http://&lt;%= SERVER_NAME %>/<%= maNav(0) %>"><%= maNav(1) %></a></li>
            <% maNav.MoveNext
            loop
            Set maNav = Nothing %>
            </ul>
+2  A: 

If your using .net 2.0 look into a asp:repeater that can bind to a datasource, if your using .net 3.5 look into a asp:listview. Those controls give you the ability to iterate through data and generate markup which is essentially what your doing.

Mcbeev
The simplest way to port this code to .NET will be to avoid WebForms until it's needed. All of the classic code works just fine in a .NET environment.
Peter J
I agree, it depends on the author's definition of conversion I guess.
Mcbeev
+2  A: 

ASP.net handles code split between several <%%> tags just fine. The problem lies elsewhere. Please edit your question to include the error message.

Peter J
So you are saying that this kind of code should work just fine?
Olav
Yes, absolutely. Classic ASP code works in a .NET environment with very little changes.
Peter J
+1  A: 

You can always use ASP.NET's data controls such as Repeater, GridView, DataList to display collections of item. And you can customize their looks by modifying the ItemTemplate. You can also include the rendering conditional inside ItemTemplate too.

For example:

   <asp:Repeater id="Repeater1" runat="server">

      <HeaderTemplate>
         <table border="1">
      </HeaderTemplate>

      <ItemTemplate>
         <tr>
            <td> <%# Container.DataItem %> </td>
         </tr>
      </ItemTemplate>

      <FooterTemplate>
         </table>
      </FooterTemplate>

   </asp:Repeater>

Taken from: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemtemplate.aspx

You can always insert conditional logic inside <%# ... %> text. Or if the logic are complicated, you can code them inside the code behind file and call them from here.

Search for "ASP.NET If inside ItemTemplate" or "ASP.NET Condition in ItemTemplate" for more info.

m3rLinEz