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
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
Use the SelectedItem property.
Nevermind. I realized, too late, that you wanted to SET and not READ.
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.Te xt = adodcRS1.recordset!RS1Desc pription
I've gotten errors with everything combination I have tried.
Set DataCombo1.SelectedItem = 3
or
Set DataCombo1.SelectedItem.Te
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.
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.bookmar k = DataCombo1.SelectedItem
Try
DataList.text = "the 1 u want"
DataList.text = "the 1 u want"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You All!