Solved

Dropdown List not grabbing Selected Value when selected

Posted on 2011-02-22
5
323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 55

Expert Comment

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

Accepted Solution

by:
Huseyin KAHRAMAN 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

705 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