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. Advertisements

  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. Advertisements

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,889
    HemaRitchie
    Dec 29, 2008
  2. suzy

    binding xml as datasource

    suzy, Apr 11, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    483
  3. ad
    Replies:
    1
    Views:
    642
    Scott Allen
    Mar 3, 2005
  4. COHENMARVIN
    Replies:
    1
    Views:
    691
    =?Utf-8?B?U3JlZWppdGggUmFtKE1DU0QuTkVUKQ==?=
    Oct 14, 2005
  5. John Chambers
    Replies:
    1
    Views:
    522
    Dave Brown
    Mar 21, 2005
  6. Mr Not So Know It All

    Binding multiple Datasource to DropDownlist

    Mr Not So Know It All, Jan 3, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    786
    Mr Not So Know It All
    Jan 3, 2007
  7. taa
    Replies:
    1
    Views:
    428
    Eliyahu Goldin
    Apr 16, 2008
  8. joe data

    Binding multiple datagrids to the same datasource

    joe data, Apr 27, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    494
    joe data
    Apr 27, 2004
Loading...