asp:DropDownList Control Issue

G

GuyInTn

Hello all,

I have an asp:dropdownlist that is dynamically filled with a query.
This part is working. The problem I have is when I change the item in
the dropdown list and submit my form, the value for the dropdown list
never changes. It always inserts the value of the first item in the
list.

Here is my dropdown:

<asp:DropDownList ID="CallReason" DataTextField="call_reason"
DataValueField="id" runat="server" />

Here is the code behind:

cmd2.CommandText = "SELECT id, call_reason FROM <TABLE>";
qlDataReader rdr = null;
cn.ConnectionString = constants.ConnectionString;
cn.Open();
cmd.Connection = cn;
objAcc.Fill_DataReader(cmd2, ref rdr);

CallReason.DataSource = rdr;
CallReason.DataBind();


Can someone tell me what I am doing wrong here?

Thanks.
 
D

DCW

You are rebinding the list and losing dropdown's persisted value. Only bind
the first time (!IsPostBack) and you'll be good.

Drew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top