I have to convert some code from classic ASP to ASP.NET
我必须将一些代码从经典ASP转换为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.
1)我如何才能最好地处理如下语法,因为代码在标记内部,似乎失败了,也许因为条件被分成几个标记。
2) Any tools or guidelines that are good on this kind of code?
2)任何有关此类代码的工具或指南?
3) Classic ADO.
3)经典的ADO。
<li><a<% if "" = myFolder then %> class="selected"<% end if %> href="http://<%= 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://<%= SERVER_NAME %>/<%= maNav(0) %>"><%= maNav(1) %></a></li>
<% maNav.MoveNext
loop
Set maNav = Nothing %>
</ul>
3 个解决方案
#1
ASP.net handles code split between several <%%> tags just fine. The problem lies elsewhere. Please edit your question to include the error message.
ASP.net处理好几个<%%>标签之间的代码分割。问题出在其他地方。请编辑您的问题以包含错误消息。
#2
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.
如果您使用.net 2.0查看可以绑定到数据源的asp:repeater,如果您使用.net 3.5查看asp:listview。这些控件使您能够迭代数据并生成标记,这基本上就是您的操作。
#3
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.
您始终可以使用ASP.NET的数据控件(如Repeater,GridView,DataList)来显示项的集合。您可以通过修改ItemTemplate来自定义其外观。您也可以在ItemTemplate中包含渲染条件。
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
摘自: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.
搜索“ASP.NET If ItemTemplate”或“ItemTemplate中的ASP.NET条件”以获取更多信息。
#1
ASP.net handles code split between several <%%> tags just fine. The problem lies elsewhere. Please edit your question to include the error message.
ASP.net处理好几个<%%>标签之间的代码分割。问题出在其他地方。请编辑您的问题以包含错误消息。
#2
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.
如果您使用.net 2.0查看可以绑定到数据源的asp:repeater,如果您使用.net 3.5查看asp:listview。这些控件使您能够迭代数据并生成标记,这基本上就是您的操作。
#3
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.
您始终可以使用ASP.NET的数据控件(如Repeater,GridView,DataList)来显示项的集合。您可以通过修改ItemTemplate来自定义其外观。您也可以在ItemTemplate中包含渲染条件。
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
摘自: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.
搜索“ASP.NET If ItemTemplate”或“ItemTemplate中的ASP.NET条件”以获取更多信息。