How to retrive value from Dropdownlist control .DataValueField


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: How to retrive value from Dropdownlist control .DataValueField

  1. #1
    Join Date
    Apr 2004
    Posts
    109

    How to retrive value from Dropdownlist control .DataValueField

    The following loop stored values.

    For intInd = 0 To ds1.Tables(0).Rows.Count - 1
    cboApp.DataValueField = ds1.Tables(0).Rows(intInd).Item(0)
    cboApp.Items.Add(ds1.Tables(0).Rows(intInd).Item(1))
    Next

    I get the value out from cboApp.Items by using cboApp.SelectedValue. How can I get the value out from cboApp.DataValueField?

    Thanks.

    Dan-Yeung

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    This works fine for me:

    lblOutput.Text = cboApp.DataValueField

    Am I missing something?
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Apr 2004
    Posts
    109
    If the dropdownlist control items are added using the loop above, cboApp.DataValueField always returns the last value that was stored in it. Both .SelectedValue and .SelectedItem return the text in the dropdownlist. And I still couldn't figure it out how to get the correct value.

    However, if the dropdownlist was binded as below, .SelectedValue and .SelectedItem.Value returns the value in .DataValueField, and .SelectedItem.Text returns the text in .DataTextField. If anyone know why, please share.

    With cboApp
    .DataSource = dsAppList.Tables(0).DefaultView
    .DataValueField = "intAppID"
    .DataTextField = "App"
    .DataBind()
    End With

    Thanks.
    Dan-Yeung

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    A DropDownList only supports one DataValueField and one DataTextField. Typically, you do not need to add items to a databound list control; you simply bind the control as in your last post, and it gets populated automatically. If you're manually populating the control, then it's not databound and you need not set the DataValueField or DataTextField properties.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center