Solved

Drop down items missing after postback

Posted on 2007-11-30
3
448 Views
Last Modified: 2013-12-16
This sounds like a dumb questions even as I am writing it, but I am adding items to a drop down list in the OnLoad.  The dropdown has autopost back enabled.  When I run it the app on the webserver and change the year in the drop down list the items I added dynamically disappear.  When I am debugging, they don't disapper.

<asp:DropDownList ID="ddlYears" runat="server" AutoPostBack="true">
        </asp:DropDownList>

'Populate ddlYears
            For i As Int32 = DateTime.Now.Year - 1 To (DateTime.Now.Year + 2)

                Dim ddlEntry As New ListItem(i.ToString(), i.ToString())
                If i = DateTime.Now.Year Then
                    ddlEntry.Selected = True
                End If
                ddlYears.Items.Insert(ddlYears.Items.Count, ddlEntry)
            Next
0
Comment
Question by:smcdrc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Expert Comment

by:Munawar Hussain
ID: 20385446
FIRST make sure you it is inside postback

if (!isPostback)
{
populate here
}

2nd check ViewState it should be enabled

 <asp:DropDownList ID="DropDownList1" EnableViewState="true"  runat="server">
        </asp:DropDownList>
0
 
LVL 2

Author Comment

by:smcdrc
ID: 20398181
It is in the !isPostBack and viewstate is enabled.  These are dynamically entered at run time.  
0
 
LVL 12

Accepted Solution

by:
Munawar Hussain earned 500 total points
ID: 20401508
Even you add Items at runtime / dynamically .. does not matter.it should keep items saved. the only condition where it could lost items is .. if you are filling dropdownlist javascrip at client side then during postback you will most likely lose items.
Is it possible to post same code (ASPX + CS) ? I may check that?
Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question