Problem With Dropdowns, Loops, Databinding and Placeholders

Reply

Join Date: Aug 2005
Posts: 11
Reputation: Athersgeo is an unknown quantity at this point 
Solved Threads: 0
Athersgeo Athersgeo is offline Offline
Newbie Poster

Problem With Dropdowns, Loops, Databinding and Placeholders

 
0
  #1
Oct 23rd, 2009
I'm in the process of trying to convert a website from classic ASP to .NET and while most of it has actually gone pretty well, this one particular page is driving me insane.

It should, in theory, be simple: One input box and three dropdown lists (for day, month and year). Where I'm having the problem is in getting the year list (in particular, though the same issue applies to the day list) to populate using a for loop (so that I can program it to automatically show current year plus five).

If I use the code I've got in a regular page (either code behind or otherwise) with no master page, everything works great.

As soon as it goes into the actual website page (which does employ a master page), it gives me a "Object reference not set to an instance of an object." error.

The sub I'm running is as follows:
  1.  
  2. Sub Populate_YearList()
  3.  
  4. 'Year list can be extended
  5. Dim intYear As Integer
  6. Dim MainContent As ContentPlaceHolder = CType(Page.Master.FindControl("ContentPlaceHolder2"), ContentPlaceHolder)
  7. Dim DropDownList4 As DropDownList = CType(MainContent.FindControl("DropDownList4"), DropDownList)
  8.  
  9. For intYear = 2009 To 2015
  10. DropDownList4.Items.Add(CStr(intYear))
  11. Next
  12.  
  13. DropDownList4.Items.FindByValue(CStr(2013)).Selected = True
  14. End Sub
  15.  

Can anyone see what I've screwed up?
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 257 | Replies: 0
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC