Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1306
  • Last Modified:

How to set SelectedItem in a DataBound Control?

Hi,
I have multiple DataList & DataCombo controls.  I would like to be able to programmatically set which item in the DataList or DataCombo is selected as a default based on input from a textbox.  It seems like it should be a simple thing to do.  However, I can't figure out how to do it.  Any help would be greatly appreciated.
Thanks
 
 
0
lkath
Asked:
lkath
1 Solution
 
GivenRandyCommented:
Use the SelectedItem property.

0
 
GivenRandyCommented:
Nevermind.  I realized, too late, that you wanted to SET and not READ.
0
 
lkathAuthor Commented:
I thought that seemed the way to go.  However, I can't get it to work.  I have tried various variations such as:
  Set DataCombo1.SelectedItem = 3
or
  Set DataCombo1.SelectedItem.Text = adodcRS1.recordset!RS1Descpription

I've gotten errors with everything combination I have tried.

0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
TimCotteeHead of Software ServicesCommented:
You need to move to the appropriate record in the underlying recordset and then refresh the datacombo.

Private Sub Command1_Click()
    Adodc1.Recordset.Find "ProductName = '" & Text1.Text & "'"
    DataCombo1.Refresh
End Sub

This example sets the selected item of the datacombo1 to the value of the text1.text property. Where the datacombo is bound to the ADODC1 data control.

0
 
wsh2Commented:
Set adodcRS1.recordset.bookmark = DataCombo1.SelectedItem
0
 
SirNickCommented:
Try

DataList.text = "the 1 u want"
0
 
digimpCommented:
after a datalist or a datacombo is linked to a database simply write

datacombo1= text1.text

0
 
lkathAuthor Commented:
Thank You All!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now