Click here to Skip to main content
15,906,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to check DataRowView null or not. I got error "The source contains no DataRows" here.

if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView drView = (DataRowView)e.Row.DataItem;
                {
                    DataTable dtChildTable1 = ((DataTable)Session["dtAll"]).Select("ID=" + Convert.ToInt32(drView["ID"])).CopyToDataTable();
}
Posted

Its better if you use boolean AND operator as follow
MSIL
if (if e.Row != null && e.Row.RowType == DataControlRowType.DataRow)
{
    DataRowView drView = (DataRowView)e.Row.DataItem;
    {
         DataTable dtChildTable1 = ((DataTable) Session["dtAll"]);
         if(dtChildTable1 != null)
         {
              DataTable dtNew = dtChildTable1.Select("ID=" + Convert.ToInt32( drView["ID"])).CopyToDataTable();
         }
    }
}

 Or <br />
you can create a reference to the DataRow[] Array instead of dtNew variable of or better to use var 
 
Share this answer
 
Comments
divesh12 28-Jul-11 13:57pm    
Hi thanx for reply, I try with your Code but When i use this its working.
Try (drView.Row != null).
 
Share this answer
 
Comments
divesh12 28-Jul-11 13:58pm    
Thanx but still the error is same "The source contains no DataRows" here.

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



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