组合框不显示

时间:2011-01-07 22:55:46

标签: asp.net ajax combobox

此问题此前已在此处提出,但作者不是很清楚,也没有得到答案(第一篇参考文献)。为什么我的组合框项目没有正确显示?它几乎就像它们在那里,但没有连接到组合框(注意我的标签,当它运行时,它显示在页面的中间而不是在组合框的正下方)。我在页面上没有错误,这很好(不同于我在VS2005中尝试这样做的时候),并且组合框显示正常,但是当我点击它时,没有任何错误。

 <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:ComboBox ID="ComboBox1" runat="server" AutoPostBack="true" 
            DropDownStyle="DropDownList">
          <asp:ListItem>thisis</asp:ListItem>
          <asp:ListItem>mynetwork</asp:ListItem>
          <asp:ListItem>getoffmyjunk</asp:ListItem>
          <asp:ListItem>itsmine</asp:ListItem>
          <asp:ListItem>illkillyou</asp:ListItem>
          <asp:ListItem>forrealz</asp:ListItem>
          <asp:ListItem>what</asp:ListItem>
          <asp:ListItem>didyousaysomething</asp:ListItem>
          <asp:ListItem>didn'tthinkso</asp:ListItem>
          <asp:ListItem>meh</asp:ListItem>
        </asp:ComboBox>
        <br />
        <asp:Label ID="lbl" runat="server">default text</asp:Label>
    </div>
    </form>
</body>
</html>

https://stackoverflow.com/questions/4322922/combo-box-items-does-not-display-below-of-combo-box-why

我和这个家伙有同样的问题: http://p2p.wrox.com/book-asp-net-ajax-programmers-reference-asp-net-2-0-asp-net-3-5-isbn-978-0-470-10998-4/80267-ajax-combobox-not-displaying-item-list-correctly.html

2 个答案:

答案 0 :(得分:0)

对于ComboBox控件,您的语法看起来不正确。您希望使用“文本”和“值”参数来获取要显示的选项。你会希望它看起来像这样:

<asp:ComboBox ID="ComboBox1" runat="server" AutoPostBack="true" DropDownStyle="DropDownList">
   <asp:ListItem Text="thisis" Value="thisis"></asp:ListItem>
   <asp:ListItem Text="mynetwork" Value="mynetwork"></asp:ListItem>
   <asp:ListItem Text="getoffmyjunk" Value="getoffmyjunk"></asp:ListItem>
</asp:ComboBox>

注意:您可能还遇到了控件标记声明的问题。例如,当我将AJAX Control Toolkit导入我的应用程序并添加适当的引用时,我最终使用标记“cc1”来表示所有AJAX Control Toolkit控件。您可能还需要仔细检查这些参考文献。

答案 1 :(得分:0)

使用toolkitscriptmanager xD左想给蒂姆答案,但他不会把他的评论作为答案;;