Keeping DropDownList from repeating databound items

Discussion in 'ASP .Net' started by Andy B., Feb 19, 2009.

  1. Andy B.

    Andy B. Guest

    I have a databound DropDownList in the HeaderTemplate of a DataList. When I
    run the page, the databound items appear twice in the DropDownList. I get my
    data from an entity framework link back to a database. So, instead of having
    these items: View all years, 2009, 2004 I have this: View all years, 2009,
    2004, 2009, 2004. Any idea how to fix this? Just a note that whenever I
    remove the DropDownList from the headerTemplate and put the
    datasource/databind for the DropDownList in an if not IsPostBack block
    everything works fine.
     
    Andy B., Feb 19, 2009
    #1
    1. Advertisements

  2. Andy B.

    lee atkinson Guest

    Maybe check to see if its already databound before binding in the
    firstplace?


    On 19/02/2009 11:43, in article , "Andy
    B." <> wrote:

    > I have a databound DropDownList in the HeaderTemplate of a DataList. When I
    > run the page, the databound items appear twice in the DropDownList. I get my
    > data from an entity framework link back to a database. So, instead of having
    > these items: View all years, 2009, 2004 I have this: View all years, 2009,
    > 2004, 2009, 2004. Any idea how to fix this? Just a note that whenever I
    > remove the DropDownList from the headerTemplate and put the
    > datasource/databind for the DropDownList in an if not IsPostBack block
    > everything works fine.
    >
    >
     
    lee atkinson, Feb 19, 2009
    #2
    1. Advertisements

  3. Andy B.

    Andy B. Guest

    [solved] Keeping DropDownList from repeating databound items

    Ok. Figured it out with your pointer there. I had the code to databind the
    DropDownList in the ItemCreated event of the DataList. Didn't think that the
    controls haven't been databound by that time yet. So my extra call to
    DropDownList.DataBind() created the second set of items.

    "lee atkinson" <> wrote in message
    news:C5C2FC9B.3489%...
    > Maybe check to see if its already databound before binding in the
    > firstplace?
    >
    >
    > On 19/02/2009 11:43, in article ,
    > "Andy
    > B." <> wrote:
    >
    >> I have a databound DropDownList in the HeaderTemplate of a DataList. When
    >> I
    >> run the page, the databound items appear twice in the DropDownList. I get
    >> my
    >> data from an entity framework link back to a database. So, instead of
    >> having
    >> these items: View all years, 2009, 2004 I have this: View all years,
    >> 2009,
    >> 2004, 2009, 2004. Any idea how to fix this? Just a note that whenever I
    >> remove the DropDownList from the headerTemplate and put the
    >> datasource/databind for the DropDownList in an if not IsPostBack block
    >> everything works fine.
    >>
    >>

    >
     
    Andy B., Feb 19, 2009
    #3
    1. Advertisements

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. =?Utf-8?B?Q2hyaXM=?=

    Keeping listbox items without resetting them each time

    =?Utf-8?B?Q2hyaXM=?=, Feb 13, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    484
    =?Utf-8?B?Q2hyaXM=?=
    Feb 13, 2005
  2. alr
    Replies:
    12
    Views:
    657
  3. rodchar
    Replies:
    0
    Views:
    608
    rodchar
    Nov 26, 2007
  4. Cirene
    Replies:
    5
    Views:
    687
    Cirene
    Jun 8, 2008
  5. Manu
    Replies:
    0
    Views:
    321
  6. Evan M.

    Disable databound dropdownlist if 0 items

    Evan M., Nov 13, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    207
    Evan M.
    Nov 13, 2006
  7. Joel Barsotti

    Can preselect databound listbox items

    Joel Barsotti, Jan 4, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    230
    Joel Barsotti
    Jan 4, 2007
  8. Lagrange
    Replies:
    1
    Views:
    790
    Lagrange
    Jan 17, 2009
Loading...