Link to home
Start Free TrialLog in
Avatar of woodje
woodjeFlag for United States of America

asked on

Dropdown List not grabbing Selected Value when selected

I have several dropdown lists I am using on my form each one of them is supplied by a database table using linq. I have defined my DataValueField and DataTextFields, and they display correct. However when I go to pull the DataValueField when I insert data to the database. The system is passing the first item from the database not the item that was selected.

With the code below. I am expecting "310332" to be inserted however it is inserting "2042356" Which is the first item in the ddl datasource.

Jeff

/// Here is the ddl setup ///
ddlEffectedSystemAdd.DataSource =  ddlSystemValues;
ddlEffectedSystemAdd.DataValueField = "SystemID";
ddlEffectedSystemAdd.DataTextField = "SystemName";
ddlEffectedSystemAdd.DataBind();           

/// And here is where I am calling the ddl in the insert ///
tt.TicketInitiator = ddlTicketInitiatorAdd.SelectedValue;

Open in new window

Avatar of HainKurt
HainKurt
Flag of Canada image

looks like you are bindind the data each time...
you should get & bind data once when page.isPostBack is false...
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, set the autopostback of the DropDownList to true.

Do this in Form_Load:

ddlTicketInitiatorAdd.AutoPostback=true;

Open in new window

Avatar of woodje

ASKER

The postback worked perfect. I forgot about that.
Which postback worked? You were given 2 approaches.