Click here to Skip to main content
15,911,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using asp.Net object data source and need to check if it is empty i want to put some logic. please help

 protected override void Page_Load(object sender, EventArgs e)
{
    if (myobjectdatasource == null)
            {
                //do something here
            }
            else
            {
                //do something here
            }
}
Posted
Updated 11-Dec-11 23:18pm
v2
Comments
Rajesh Anuhya 12-Dec-11 5:18am    
What is the Error you are getting?

1 solution

In the ObjectDataSource's Selected method, cast e.ReturnValue to whatever container/collection object you expect to return and test if it is empty or null.

eg:

C#
if (((ArrayList)e.ReturnValue).Count == 0 || (ArrayList)e.ReturnValue == null)
{

       lblNoOrders.Text = "There are 0 results returned.";
}
 
Share this answer
 
Comments
Gufran_khan 12-Dec-11 5:50am    
Thanks for your kind reply.
but i cannot cast. as you can check in code i need to check in pageload event. and i cannot change BLL where selected method is defined.
jiji2663 8-Jul-13 2:35am    
Great...
In ObjectDataSource's Selected method
if(e.ReturnValue==null)
lblNoOrders.Text = "There are 0 results returned.";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900