Link to home
Start Free TrialLog in
Avatar of lkath
lkath

asked on

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
 
 
Avatar of GivenRandy
GivenRandy

Use the SelectedItem property.

Nevermind.  I realized, too late, that you wanted to SET and not READ.
Avatar of lkath

ASKER

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.

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.

Set adodcRS1.recordset.bookmark = DataCombo1.SelectedItem
Try

DataList.text = "the 1 u want"
ASKER CERTIFIED SOLUTION
Avatar of digimp
digimp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lkath

ASKER

Thank You All!