C#/ASP.NET - Cannot have repeater inside HTMLselect

我是研究僧i 提交于 2019-12-11 03:07:44

问题


I'm trying to display some data within a select using the following code:

<select name="area" runat="server">
    <asp:Repeater ID="RepeaterArea" runat="server">
    <ItemTemplate>
        <option value="<%# Eval('Id') %>" runat="server"><%# Eval("Area") %></option>
    </ItemTemplate>
    </asp:Repeater>
</select>

I get an error stating that I cannot have a repeater inside a HTMLSelect.

Any suggestions would be very welcome, thanks!


回答1:


Remove the runat="server". You can get the value by Request.Form["area"].ToString()




回答2:


Why is your <select> being run at the server? Remove that attribute and it should compile fine.

As the error says, the only valid child element of an HtmlSelect are options or optgroup thingy, not asp repeaters (even if they do create options, the compiler isn't aware of this).




回答3:


Try removing the runat="server" from select tag



来源:https://stackoverflow.com/questions/18661030/c-asp-net-cannot-have-repeater-inside-htmlselect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!