Solved

How to set SelectedItem in a DataBound Control?

Posted on 2000-05-05
8
1,186 Views
Last Modified: 2010-08-05
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
Comment
Question by:lkath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2780617
Use the SelectedItem property.

0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2780665
Nevermind.  I realized, too late, that you wanted to SET and not READ.
0
 

Author Comment

by:lkath
ID: 2780718
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 43

Expert Comment

by:TimCottee
ID: 2780759
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
 
LVL 14

Expert Comment

by:wsh2
ID: 2780770
Set adodcRS1.recordset.bookmark = DataCombo1.SelectedItem
0
 
LVL 3

Expert Comment

by:SirNick
ID: 2782326
Try

DataList.text = "the 1 u want"
0
 

Accepted Solution

by:
digimp earned 50 total points
ID: 2783981
after a datalist or a datacombo is linked to a database simply write

datacombo1= text1.text

0
 

Author Comment

by:lkath
ID: 2788284
Thank You All!
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA - If Bookmark = "XXBOOKMARKXX" then 15 67
Problem to line 23 80
SQL Server 2012 to SQL Server 2016 24 56
Create a list of Worksheets based on Cell Value 14 32
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question