Solved

Dropdown List not grabbing Selected Value when selected

Posted on 2011-02-22
5
280 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:woodje
  • 2
  • 2
5 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 34955477
looks like you are bindind the data each time...
you should get & bind data once when page.isPostBack is false...
0
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 34955494
like this:

void Page_Load(){
   if (Page.IsPostBack){
     getMyData();
   }
}

where getMyData() is a procedure that loads data into drop down... if you do not do this, and always bind data, thenselected item will be lost, and selectedindex will be set to 0, first item every time page loads...
0
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 34955593
Yes, set the autopostback of the DropDownList to true.

Do this in Form_Load:

ddlTicketInitiatorAdd.AutoPostback=true;

Open in new window

0
 

Author Closing Comment

by:woodje
ID: 34955615
The postback worked perfect. I forgot about that.
0
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 34956491
Which postback worked? You were given 2 approaches.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now