c# - How do I populate a dropdown list with the past 30 days of dates -


i trying populate dropdown list past 30 dates , receiving error:

an exception of type 'system.outofmemoryexception' occurred in mscorlib.dll not handled in user code

this function fill drop down list:

public void filldates(int numdaysback) {     (datetime d = datetime.now.adddays(-numdaysback); d < datetime.now; d.adddays(1))     {         ddmiscdatelist.items.add(d.toshortdatestring());     }     ddmiscdatelist.items.add("other"); } 

i calling function on load , using 30 numdaysback. how can write more efficiently not receive error?

datetime.adddays() returns new instance of datetime. doesn't change d variable. because of have infinite loop. can fix it

public void filldates(int numdaysback) {     (datetime d = datetime.now.adddays(-numdaysback); d < datetime.now; d = d.adddays(1))     {         ddmiscdatelist.items.add(d.toshortdatestring());     }     ddmiscdatelist.items.add("other"); } 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -