如何将从方法返回的列表<string>添加到类型为string?</string>的数组中

时间:2011-04-27 04:05:47

标签: c# asp.net html

我正在使用列表动态绑定html选择控件。问题是,无法在aspx页面中声明列表。如何绑定返回到选择控件的列表中的每个元素?代码如下所示:

 <select title="select table" id="ddlTableNames" onchange="getTableName()" onload="SetTableNameToParameter()">
            <!-- onload="fromHtmlDropDown()" -->
            <option>Select</option>
            <%

              for (int i = 0; i < metaData.GetTables().Count; i++)
              {
            %>
            <option>
              <%=metaData.GetTables()[i]%></option> // I need to store the return value to something. Dont know the array syntax for this on an aspx page
            <% 
              } 
            %>
          </select>

1 个答案:

答案 0 :(得分:0)

我不是100%肯定你在这里要求的东西,但假设返回的列表/数组中包含的值有意义显示为字符串(它看起来像你的例子),那么以下可能是一种更简单的方法:

<select title="select table" id="ddlTableNames" onchange="getTableName()" onload="SetTableNameToParameter()">
<option>Select</option>
<% foreach (var table in metaData.GetTables()) { %>
    <option><%= table %></option>
<% } %>

这解决了你的问题吗?如果没有,请帮助我准确理解您要解决的问题。

干杯, 克里斯