Solved

Dropdown List not grabbing Selected Value when selected

Posted on 2011-02-22
5
317 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 52

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 52

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp web application 3 43
Build a string of emails from a gridview 2 20
Adjust the codes 3 38
Fastest way to get file count in MS Server 2012 3 14
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

697 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