Asp classic asp classic中基于变量值的循环

Asp classic asp classic中基于变量值的循环,asp-classic,Asp Classic,我必须根据变量的值输出一个表。我有一个唯一的带有变量的表块。根据视图的不同,应该有一个循环来重新读取表 变量可以有两个或三个值,或者两者都有。我必须在所有情况下输出带有视图1的表 例1: 输出: <table> <tr> <td>Table For View One</td> </tr> </table> <table> <tr> <td&

我必须根据变量的值输出一个表。我有一个唯一的带有变量的表块。根据视图的不同,应该有一个循环来重新读取表

变量可以有两个或三个值,或者两者都有。我必须在所有情况下输出带有视图1的表

例1:

输出:

<table>
    <tr>
        <td>Table For View One</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View Two</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View Three</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View One</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View Two</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View One</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View Three</td>
    </tr>
</table>
输出:

<table>
    <tr>
        <td>Table For View One</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View Two</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View Three</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View One</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View Two</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View One</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View Three</td>
    </tr>
</table>
输出:

<table>
    <tr>
        <td>Table For View One</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View Two</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View Three</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View One</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View Two</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View One</td>
    </tr>
</table>
<table>
    <tr>
        <td>Table For View Three</td>
    </tr>
</table>
尝试了一些时间和时间,但没有成功

<%
i=2
Do While i = 0
%>
<table>
    <tr>
        <td><% Response.Write i %></td>
    </tr>
</table>
<%
   i=i-1
Loop
%>

我想像这样的东西会很好用的。我只使用if-else-if。我还支持观点可以等于二、三或三、二的观点

<%if Views = "Two" then%>
    <table>
        <tr>
            <td>Table For View One</td>
        </tr>
    </table>
    <table>
        <tr>
            <td>Table For View Two</td>
        </tr>
    </table>
<%else if Views = "Three"%>
    <table>
        <tr>
        <td>Table For View One</td>
        </tr>
    </table>
    <table>
        <tr>
            <td>Table For View Three</td>
        </tr>
    </table>
<%else if Views = "Two, Three"%>
    <table>
        <tr>
            <td>Table For View One</td>
       </tr>
    </table>
    <table>
        <tr>
            <td>Table For View Two</td>
        </tr>
    </table>
    <table>
        <tr>
            <td>Table For View Three</td>
        </tr>
    </table>
<%else if Views = "Three, Two"%>
     <table>
        <tr>
            <td>Table For View One</td>
        </tr>
    </table>
    <table>
        <tr>
            <td>Table For View Three</td>
        </tr>
    </table>
    <table>
        <tr>
            <td>Table For View Two</td>
        </tr>
    </table>
<%end if%>

有多种方法可以实现这一点,但在不改变代码的情况下,可以通过使用逗号作为分隔符将Views变量拆分为数组来实现。一旦获得数组,使用For循环迭代视图,并使用Select语句返回正确的视图

由于您指定表1将始终包含在循环中,因此它被保留在循环之外

像这样的东西没有经过测试

视图一的表格 然后,如果你通过了2,例如3,你的输出就会像这样

视图一的表格 第二视图的表格 第三视图的表格 基于OP反馈的更新

如果您的问题中没有明确的定义,那么只需删除ShowTable过程中的和行内定义,这将创建表的内部和一系列表行。 然后在上面的示例代码中,只需在代码的开头和后面添加,这将把动态生成的表行封装到一个表中

试试这个:


感谢您的回复,但是表块实际上是一个唯一的信息块。基于视图,我将循环并输出当前值。抱歉,也许这篇文章不清楚。这不是你的错@CodyEsmay OP没有清楚地描述他们的期望,我对我的答案做了同样的假设。我假设OP谈论的唯一块只是意味着OP不希望表重复,因此我给出了答案。请显示您现在拥有的实际代码,以便更容易理解表的唯一块的含义。@SearchAndResQ,已添加。谢谢,2号和3号怎么了?还是会是2和3?在你的编辑中,我是视图?对不起,我不明白。代码只是一个尝试。i=2将是视图=2,3感谢您的时间@Lankymart。但我只有一个表块,视图一、二和三将使用同一块来显示数据。我在表中有一些变量,所以如果有一个、两个或三个变量,它会显示不同的信息。@Khrys这不是你的问题所显示的,是吗??通过你的问题来展示你想要得到什么样的输出,我将修改我的答案。这就是输出的一个例子。我希望的代码在问题的结尾。@Khrys我假设的代码是您的尝试,然后根据您在问题中显示的输出编写了我的代码。如果这不是您想要的,请显示您期望的输出。@Khrys如果您只想将所有内容都放在一个表中,而您的问题并不清楚,请从代码中删除and,然后在前后添加它们,该方法仍然有效。看起来我们都误解了OPs要求,但老实说,这是因为OP没有足够详细地描述他们想要什么,他们期望什么,他们尝试了什么。这个问题本应被关闭/搁置。现在我将等待;对于判决:这正是我所希望的。对不起,我不太清楚。谢谢。@Khrys你查过我的支票了吗?这个答案有什么不同,对不起,你被骗了。我不是在骗你。我刚刚测试了@SearchAndResQ,它就工作了。我试过你的,但没法用。但我真的很感谢你花时间来帮助我。批准一个答案并不意味着另一个答案是错误的,但我批准的答案更方便、直截了当,而且有效。