Posted on: 11/19/2013 7:52:22 PM | Views : 350

I have a listview defined on my page that contains an EmptyDataTemplate.  When data is returned from the database and bound to the listview, everything works as expected. When no rows are returned, however, rather than displaying the EmptyDataTemplate an "Object reference not set to an instance of an object" error is thrown when the binding is attempted.  
This is the code for binding to the ListView:
DataAccessDataContext db = new DataAccessDataContext(); lstPSC.DataSource = db.GetAllPendingPSCRequests("", ""); lstPSC.InsertItemPosition = InsertItemPosition.None; lstPSC.DataBind(); <== this is where the error is thrown I understand why the error is being thrown, but not how to both test for the empty dataset while also displaying the EmptyDataTemplate.  What am I missing?

Go to the complete details ...