-
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
-
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!
-
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
-
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
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|