我只想簡單地點擊一個按鈕,文本框中的文本就會自動添加爲列表框中的一個項目。這不應該是直截了當的嗎?調試時,項目被添加,我可以通過觀看ListBox1.Items [0]來查看文本,但是網頁中沒有顯示任何內容。我在控制檯應用程序中遇到了同樣的問題,我沒有解決這個問題!有人可以指導我做什麼我錯了嗎?不使用asp列表框
protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Add(new ListItem(TextBox1.Text));
}
非常感謝
編輯:
在過去的項目中,我用DataSource屬性,它完美地工作。我從來沒有設法使用添加項目!可能是有某種刷新或更新?
頁面代碼:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:ListBox ID="ListBox1" runat="server" Height="150px" Width="295px"></asp:ListBox>
<asp:UpdatePanel ID="updatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
其空的!,但這是我的aspx頁面。 asp:ScriptManager> asp:TextBox> asp>:UpdatePanel> –
test
2012-02-15 20:26:05