我有一個列表框,其中包含6個項目。在選定的索引列表框中改變事件的標籤文本的文本被改變爲選擇的項目值。列表框的選擇模式是多重的。我想要 當用戶選擇一個項目時,它應該從列表框中移除並添加到標籤文本中。 用戶可以刪除選定的項目1 2或全部 我不使用文本框,因爲我只想列表框項目可以選擇。 我的HTML是如何從asp.net中的列表框的選定項刪除
<asp:Label ID="lbl_mar_cat" runat="server" Width="100%" Font-Size="Small"></asp:Label>
<asp:ListBox ID="listbox_mar" runat="server" SelectionMode="Multiple"
CssClass="listbox" AutoPostBack="True"
onselectedindexchanged="BulletedList1_SelectedIndexChanged" >
<asp:ListItem Value="Doesn't Matter">Doesn't Matter</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>Divorced</asp:ListItem>
</asp:ListBox>
我的服務器端代碼
if (listbox_mar.SelectedValue == "Doesn't Matter")
{
lbl_mar_cat.Text = "Doesn't Matter";
}
else
{
if (lbl_mar_cat.Text == "")
{
lbl_mar_cat.Text = listbox_mar.SelectedValue.ToString();
}
else
{
lbl_mar_cat.Text += ", " + listbox_mar.SelectedValue.ToString();
}
}
展示你工作的首位.. –