DropDownList not maintaining viewstate

Discussion in 'ASP .Net' started by sklett, Apr 7, 2004.

  1. sklett

    sklett Guest

    I have 2 dropdownlist on a page. They have ViewState = true. After I
    submit to the page, the selection in the DropDownList is lost. I set a
    break in the Page_Load event to make sure that I wasn't re-binding them
    somehow... I'm not. So shouldn't they maintain their selection?

    Anything you can think of to check?

    Thanks-
    Steve
    sklett, Apr 7, 2004
    #1
    1. Advertising

  2. DropDownList must remember their selection!
    I have this example and it works fine...
    This page when selected value change make a postback.
    Selected value in DropDownList never change.

    [C# - CodeBehind]
    if (!IsPostBack)
    {
    ArrayList al = new ArrayList();
    al.Add("aa");
    al.Add("bb");
    al.Add("cc");
    DropDownList1.DataSource = al;
    DropDownList1.DataBind();

    al.Add("dd");
    DropDownList2.DataSource = al;
    DropDownList2.DataBind();
    }

    [ASPX page]
    <asp:DropDownList AutoPostBack="True" id="DropDownList1"
    runat="server"></asp:DropDownList>
    <asp:DropDownList AutoPostBack="True" id="DropDownList2"
    runat="server"></asp:DropDownList>

    Brun


    "sklett" <> wrote in message
    news:%...
    > I have 2 dropdownlist on a page. They have ViewState = true. After I
    > submit to the page, the selection in the DropDownList is lost. I set a
    > break in the Page_Load event to make sure that I wasn't re-binding them
    > somehow... I'm not. So shouldn't they maintain their selection?
    >
    > Anything you can think of to check?
    >
    > Thanks-
    > Steve
    >
    >
    Bruno Sirianni, Apr 8, 2004
    #2
    1. Advertising

  3. sklett

    sklett Guest

    That is really odd, I have 2-3 pages that all have the opposite behavior.

    If I have a dropdownlist with 3 items, a, b, and c

    Auto postback set to true

    if I select 'b', when the page is rendered after the post back, 'a' is
    selected.

    I don't know what to do differently...


    Thanks for the response though, looks like I have gremlins somewhere ;(


    "Bruno Sirianni" <> wrote in message
    news:5Bfdc.30596$...
    > DropDownList must remember their selection!
    > I have this example and it works fine...
    > This page when selected value change make a postback.
    > Selected value in DropDownList never change.
    >
    > [C# - CodeBehind]
    > if (!IsPostBack)
    > {
    > ArrayList al = new ArrayList();
    > al.Add("aa");
    > al.Add("bb");
    > al.Add("cc");
    > DropDownList1.DataSource = al;
    > DropDownList1.DataBind();
    >
    > al.Add("dd");
    > DropDownList2.DataSource = al;
    > DropDownList2.DataBind();
    > }
    >
    > [ASPX page]
    > <asp:DropDownList AutoPostBack="True" id="DropDownList1"
    > runat="server"></asp:DropDownList>
    > <asp:DropDownList AutoPostBack="True" id="DropDownList2"
    > runat="server"></asp:DropDownList>
    >
    > Brun
    >
    >
    > "sklett" <> wrote in message
    > news:%...
    > > I have 2 dropdownlist on a page. They have ViewState = true. After I
    > > submit to the page, the selection in the DropDownList is lost. I set a
    > > break in the Page_Load event to make sure that I wasn't re-binding them
    > > somehow... I'm not. So shouldn't they maintain their selection?
    > >
    > > Anything you can think of to check?
    > >
    > > Thanks-
    > > Steve
    > >
    > >

    >
    >
    sklett, Apr 8, 2004
    #3
  4. sklett

    Jim Corey Guest

    I got stumped for awhile on a similar situation when
    I set the item values to something other than the item text.

    So for example if the resulting html looked like this:
    <option value="2">Abel</option>
    <option value="3">Baker</option>
    <option value="2">Charlie</option>

    and I selected 'Charlie', when the form posted back
    the first item with the selected value (2 in this case)
    would display, so 'Abel' would be displayed.

    HTH,
    Jim




    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Jim Corey, Apr 8, 2004
    #4
  5. sklett

    sklett Guest

    Jim,

    Yeah, that would be a fun one to find ;)
    however, that is not the case for me. I set a breakpoint in the page_load
    to check what the dropdown list's selected index was and it was correct IE:
    if I had selected the 3rd item before postback, the SelectedIndex value was
    2

    but once the page is rendered... it's back to selecting the first item.

    so strange.

    Thanks for sharing your situation though, will come in handy some day!


    "Jim Corey" <> wrote in message
    news:...
    > I got stumped for awhile on a similar situation when
    > I set the item values to something other than the item text.
    >
    > So for example if the resulting html looked like this:
    > <option value="2">Abel</option>
    > <option value="3">Baker</option>
    > <option value="2">Charlie</option>
    >
    > and I selected 'Charlie', when the form posted back
    > the first item with the selected value (2 in this case)
    > would display, so 'Abel' would be displayed.
    >
    > HTH,
    > Jim
    >
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    sklett, Apr 8, 2004
    #5
    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. Dinesh Upare
    Replies:
    0
    Views:
    385
    Dinesh Upare
    Jul 16, 2003
  2. Charlie@CBFC
    Replies:
    0
    Views:
    459
    Charlie@CBFC
    Apr 2, 2005
  3. Steve Murphy
    Replies:
    2
    Views:
    747
    =?Utf-8?B?Sm9l?=
    Jan 15, 2006
  4. Udit
    Replies:
    3
    Views:
    122
  5. Carlos A. Manzanares

    DropDownList not maintaining viewstate

    Carlos A. Manzanares, Nov 10, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    120
    Carlos A. Manzanares
    Nov 10, 2003
Loading...

Share This Page