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. Advertising

  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. Advertising

  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. 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. rodchar
    Replies:
    0
    Views:
    397
    rodchar
    Nov 26, 2007
  2. Cirene
    Replies:
    5
    Views:
    485
    Cirene
    Jun 8, 2008
  3. Manu
    Replies:
    0
    Views:
    171
  4. Evan M.

    Disable databound dropdownlist if 0 items

    Evan M., Nov 13, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    127
    Evan M.
    Nov 13, 2006
  5. Lagrange
    Replies:
    1
    Views:
    568
    Lagrange
    Jan 17, 2009
Loading...

Share This Page