Thursday, March 29, 2012

List Box Code Behind Problem

I have a list box called cboProducts with a code behind function called cboProducts_SelectedIndexChanged() that's associated with the IndexChanged event.

Here's the code behind function

Public Sub cboProducts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboProducts.SelectedIndexChanged

Dim i

i = cboProducts.SelectedIndex
txtBox.Text = cboProducts.Items(selIndex).Text
End Sub


The problem is that "i" never changes from -1 no matter which option I select.

I'm trying to capture the users selected index in the list box.

What am I doing wrong?

thanks.

ddMaybe the problem is in the Page_Load event where you're probably binding a datasource to the list with products. The point is, you should a "if not page.IsPostback then" decision structure, so that the data is only bound to the controls when the page is loaded the very first time (not during postbacks). Does this help you to solve your problem?
That did it.

Thanks a million.

doug

0 comments:

Post a Comment