Drop Down List, AutoPostBack

Z

Zamdrist

I swear if I have to 'relearn' how AutoPostBack, EnableViewState and
Me.IsPostBack works, or should work, I'm going to literally tear my
hair out.

I've got a pretty simple form, couple of text boxes, a check box, a
drop down list and a button.

The drop down list is populated via code, and that works fine. The
TextValue is set to a one field returned by a stored procedure, as is
the ValueField set to an associated numeric value.

When I hit the command button to submit and run my code, the value
selected in the drop down list changes. The values listed in the drop
down list are not unique, but the text values are.

I've tried various combination of AutoPostBack = True, False,
EnableViewState = True, False. But I cannot get it working as it
should. The value selected in the drop down list shouldn't change, as
its value depends on my code working correctly. Here is what I have in
the Page Load event:

If Not Me.IsPostBack Then
If adoConn_FirmApps.State <> ConnectionState.Open Then
adoConn_FirmApps.Open()
adoComm_SubClass.Connection = adoConn_FirmApps
adoComm_SubClass.CommandType = CommandType.StoredProcedure
adoComm_SubClass.CommandText = "CI_SubClassList"
With ddlSubClass
.DataSource =
adoComm_SubClass.ExecuteReader(CommandBehavior.CloseConnection)
.DataTextField = "SubClass"
.DataValueField = "SubClassType"
.DataBind()
End With
End If

Any help, advice or suggestions would be greatly appreciated! Thanks!
 
Z

Zamdrist

Turns out this had nothing to do with PostBack behavior, and
everything to do with the drop down list DataValueField not having a
unique value. So when the page reloaded, the selection changed to the
first DataTextField. I resolved this by adding a third field to my
stored procedure that combined the Text and Value fields to use as the
DataValueField, and later just trimmed off the part I wanted from it
for use later.

Lesson: Drop Down List DataValueField values should always contain
unique values.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top