View Full Version : dropdownlist on asp
meidianakusuma
01-13-2009, 04:04 AM
guys, i'm newbie in asp.net..
hmm can i make the choice that i choose in drop down list disappear after being chosen??
vinyl-junkie
01-13-2009, 05:32 AM
Doing this will remove it from the selection list.
myDDList.SelectedItem.Enabled = false;
where myDDList is the name of your dropdownlist control.
meidianakusuma
01-13-2009, 09:48 AM
i got it,
but why after i choose the first one, and the i want to choose another, it replace, not added??
here my code
Sub ok(ByVal sender As Object, ByVal e As EventArgs)
boxText.Text = DDL1.SelectedItem.Text
DDL1.SelectedItem.Enabled = false
End Sub
country:
<asp:DropDownList ID="DDL1" runat="server" >
<asp:ListItem Value="Indonesia"></asp:ListItem>
<asp:ListItem Value="Malaysia"></asp:ListItem>
<asp:ListItem Value="Brunei"></asp:ListItem>
</asp:DropDownList><br />
<asp:Button id="btn1" Text="OK" OnClick="ok" runat="server" />
<asp:textbox id="boxText" runat="server" TextMode="MultiLine" Columns="50" Rows="6" />
Freon22
01-13-2009, 09:03 PM
Because you are replacing the text within the textbox.
boxText.Text = DDL1.SelectedItem.Text
Try something like this.
boxText.Text += DDL1.SelectedItem.Text + "\n"
The += adds the new text to the existing text, the \n makes a new line for the new text.
btw: vinyl-junkie Thanks I did not know it was so easy to remove items from a dropdownlist. Thanks again.
SouthwaterDave
01-13-2009, 09:46 PM
"\n" may work in C# but in VB.NET I think you would need vbCrLf, or possibly vbLf.
Freon22
01-13-2009, 10:07 PM
You are right. I am not into VB but he still has to do something along those line.
In C# works fine, not sure in VB he can use vbNewLine also I think. Not sure if the += will add new text to the textbox in VB.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.