Exception for Datalist inside Formview when Datalist has no items.
Posted on 2007-04-03
I keep getting this error even though my web app seems to run properly:
System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.NullReferenceException: Object reference not set to an instance of an object.
This error is produced by this code:
Protected Sub FormView1_ItemCreated(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.ItemCreated
Dim dl As DataList = FormView1.FindControl("DataList1")
AddHandler dl.ItemCommand, AddressOf DataList1_ItemCommand
Basically, I have a datalist inside a formview. The datalist loads a bunch of thumbnails, so I added an event handler so that the image shows (in the current page) whenever someone clicks on a thumbnail.
However, I think this error is being produced when the Datalist has no items. I'm not really sure. Any IDeas?