?
Solved

Dropdown List not grabbing Selected Value when selected

Posted on 2011-02-22
5
Medium Priority
?
328 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 58

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 58

Accepted Solution

by:
HainKurt earned 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

765 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