Listbox binding to datasource problem?

Discussion in 'ASP .Net Web Controls' started by Dickson, Oct 25, 2004.

  1. Dickson

    Dickson Guest

    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.
    Dickson, Oct 25, 2004
    #1
    1. Advertising

  2. Dickson wrote:
    > 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

    http://www.4GuysFromRolla.com

    * When you think ASP.NET, think 4GuysFromRolla.com!
    Scott Mitchell [MVP], Oct 25, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DesignerX
    Replies:
    5
    Views:
    19,637
    HemaRitchie
    Dec 29, 2008
  2. suzy

    binding xml as datasource

    suzy, Apr 11, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    383
  3. ad
    Replies:
    1
    Views:
    564
    Scott Allen
    Mar 3, 2005
  4. COHENMARVIN
    Replies:
    1
    Views:
    554
    =?Utf-8?B?U3JlZWppdGggUmFtKE1DU0QuTkVUKQ==?=
    Oct 14, 2005
  5. John Chambers
    Replies:
    1
    Views:
    420
    Dave Brown
    Mar 21, 2005
Loading...

Share This Page