OnSelectedIndexChanged not working...

rangerstud620

Freshman
Joined
Jun 14, 2005
Messages
27
I'm in the process of switching my apps from Access to SQL2000. Everything was working fine with Access but now as I'm making the switch to SQL, I'm having problems.

First, when I click an item in a ListBox, the selectedindex does not change, it stays at 1.
Code:
<asp:listbox ID="ListBoxMaster" runat="server" AutoPostBack="true" Rows="22" Width="300" DataValueField="LEAD_ID" DataTextField="COMPANY" OnSelectedIndexChanged="SelIndexChange" />
The following code in SelIndexChange always returns the value of 1, no matter which item in the list I select:
Code:
Dim LeadID as integer = ListBoxMaster.SelectedItem.Value

Second, when I pick an item from a dropdownlist, the item I select appears to be the actual selecteditem in the ddl, but when I try to update the db the value returned is the same as the original value in the db.
Code:
<asp:dropdownlist ID="ddlSalesperson" runat="server" Enabled="false" Width="100" DataValueField="SALES_NUM" DataTextField="REVERSE_NAME" DataSource="<%# FillSales() %>" />
The following code always returns the original value in the database when I try to update the db.
Code:
param = cmd.Parameters.Add("@Salesperson", SqlDbType.Char)
param.Value = DirectCast(di.FindControl("ddlSalesperson"), dropdownlist).SelectedValue

It seems none of the selectedindexchanged events are being raised. I'm lost as to what is wrong now that I'm using SQL. Any ideas what I'm doing wrong?
 
Last edited:
I don't know if this would work, but if you are using the .NET Framework v1.1, you could try ListBoxMaster.SelectedValue .

Also, I noticed this on MSDN. On the ListControl.SelectedIndexChanged event description, it says:

MSDN said:
The SelectedIndexChanged event is raised when the selection from the list control changes between posts to the server.

Note A list control must persist some values between posts to the server for this event to work correctly. Be sure that view state is enabled for the list control.

And under the Control.EnableViewState property:

MSDN said:
There are times when it is appropriate to disable view state, particularly to improve application performance. For example, if you are loading a database request into a server control, set this property to false. If you do not, processor time will be wasted loading view state into the server control that will only be overridden by the database query.

So perhaps there is a conflict between the view state necessary for the proper functioning of the event, and the method of loading the data?
 
Last edited:
Back
Top