asp:DropDownList Control Issue

Discussion in 'ASP .Net Web Controls' started by GuyInTn, Mar 28, 2007.

  1. GuyInTn

    GuyInTn Guest

    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.
     
    GuyInTn, Mar 28, 2007
    #1
    1. Advertising

  2. GuyInTn

    DCW Guest

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

    Drew


    "GuyInTn" wrote:

    > 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.
    >
    >
     
    DCW, Mar 28, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gunjan Garg

    Issue with dropdownlist in a user control

    Gunjan Garg, Jun 28, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    477
    Gunjan Garg
    Jun 28, 2005
  2. mr2_93
    Replies:
    1
    Views:
    3,615
    mr2_93
    Oct 2, 2005
  3. tshad
    Replies:
    8
    Views:
    2,239
    tshad
    Oct 19, 2005
  4. jobs
    Replies:
    1
    Views:
    1,841
    Masudur
    Jul 15, 2007
  5. E
    Replies:
    2
    Views:
    139
Loading...

Share This Page