Listbox binding to datasource problem?

D

Dickson

Need some help on listbox which bind to datasource. Here is what i did :-

Dim sql As String = "SELECT supp_code,supp_name FROM
tblSupplier"
Dim DA As SqlDataAdapter = New SqlDataAdapter(sql, conn_str)
Dim DS As New DataSet

DA.Fill(DS, "Supplier")

lbListSupplier.DataSource = DS.Tables("Supplier").DefaultView
lbListSupplier.DataTextField = "supp_name"
lbListSupplier.DataValueField = "supp_code"
lbListSupplier.DataBind()

My problem is how can I delete an item from the listbox or add an item into
the listbox since it was bind to a datasource.
I do not want to re-populate the listbox again by querying the database.

Another problem is since the listbox is bind to a datatable, is that any way
I can use function like CType to extract the data
bind to listbox and put into a datatable? Thanks.
 
S

Scott Mitchell [MVP]

Dickson said:
My problem is how can I delete an item from the listbox or add an item into
the listbox since it was bind to a datasource.
I do not want to re-populate the listbox again by querying the database.

The DropDownList's Items property has methods like Add(), Insert(),
Remove(), and RemoveAt() that can be used to add/remove items from the DDL.

hth

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Set DataSource 0
DataSource 4
DropDownList Binding to LINQ DataSource 0
Simple Binding? 0
Binding problem 0
ListBox problem 1
Paged Datasource memory usage 0
listbox control in devexpress modal popup 0

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top