Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox populates textbox with only first record / not selected item

Status
Not open for further replies.

bubberz

Programmer
Dec 23, 2004
117
US
I have a listbox that's populated in the Page_PreRender handler:
Dim strResSQL As String
...code to build strResSQL

Dim cmdRes As New OleDbCommand(strResSQL, Con1)
Con1.Open()
Dim myResRDR As OleDbDataReader = cmdRes.ExecuteReader()
If myResRDR.HasRows = True Then
listResource.DataSource = myResRDR
listResource.DataTextField = "Expr3"
listResource.DataValueField = "GroupCode"
listResource.DataBind()
End Sub

What I want to do is populate a text box right above the list box with the item selected, so I tried the following for the list box:
txtBox.Text = list.SelectedItem.ToString()

The above code only populates the listbox's first item.
I do have "PostBack"=True for the listbox
 
checkai,
Yes, you're correct. It's what you've sent above.
I'm trying to figure out if I should:
1. place that "txtResource.Text =" portion somewhere else
2. bind it with <%# %> for the listbox's selected item
3. build and bind the 3rd listbox somewhere else
4. Why is the first record always populating?

This is drivin' me nuts!...I know it can't be this hard.
 
so when you populate the 3rd list box the text box is empty?...can you post what's in your page load?

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
checkai,
This is all that's in my page load (it's only to populate the first ddl):

If (Not Page.IsPostBack) Then
DAddl1.Fill(DsDivision1, "ResourceLocator-DivGroup")
ddlDivision.DataBind()
ddlDivision.Items.Insert(0, "Select Division From List")
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top