Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to set SelectedItem in a DataBound Control?

Posted on 2000-05-05
8
Medium Priority
?
1,242 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
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
Technology Partners: 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 200 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

926 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