Hi Paul,
You can use the RemoveAt method for that. You need to locate the item and
get its index. Using the index value you can remove it.
Some code below. Let us know if this helps?
Ken
Microsoft MVP [ASP.NET]
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
DropDownList1.DataSource = CreateDataSource()
DropDownList1.DataTextField = "StringValue"
DropDownList1.DataValueField = "IntegerValue"
DropDownList1.DataBind()
End If
End Sub
Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
DropDownList1.Items.RemoveAt _
(DropDownList1.Items.IndexOf _
(DropDownList1.Items.FindByText("Item 2")))
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 4
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
<form id="Form1" method="post" runat="server">
<P>
<asp:DropDownList id="DropDownList1"
runat="server"></asp:DropDownList></P>
<P>
<asp:Button id="Button1" runat="server" Text="Remove
2"></asp:Button></P>
</form>
"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:DB**********************************@microsof t.com...
Hi I have a dropdown listbox that is populated by binding to a dataset.
Anyhow just wondering if anyone knows how to remove one of the items in
the
dropdown list in code after the dataset has populated it?
thanks.
--
Paul G
Software engineer.