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

2019-07-19 06:12发布

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!

3条回答
趁早两清
2楼-- · 2019-07-19 06:22

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楼-- · 2019-07-19 06:28

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

查看更多
疯言疯语
4楼-- · 2019-07-19 06:46

Try removing the runat="server" from select tag

查看更多
登录 后发表回答