woodje
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
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;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, set the autopostback of the DropDownList to true.
Do this in Form_Load:
Do this in Form_Load:
ddlTicketInitiatorAdd.AutoPostback=true;
ASKER
The postback worked perfect. I forgot about that.
Which postback worked? You were given 2 approaches.
you should get & bind data once when page.isPostBack is false...