Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi,

please find below code.It will through an error 'The source contains no DataRow' if ithe row is empty..How to handle this ??


C#
if (dtTemSec.Rows.Count > 0)
                   {
                       grdStepDetails.DataSource = dtTemSec.AsEnumerable()
                                       .Where(x => x.Field<string>("Status") != "D" && x.Field<string>("ID") == "ST" && x.Field<int>("Folder") == folder)
                                       .CopyToDataTable();
                       grdStepDetails.DataBind();
                       ClientScript.RegisterStartupScript(GetType(), "Val", "ShowStepPopup();", true);
                   }
                   else
                   {
                       grdStepDetails.DataSource = null;
                       grdStepDetails.DataBind();
                       ClientScript.RegisterStartupScript(GetType(), "Val", "ShowStepPopup();", true);
                   }
Posted
Comments
Member 12700993 23-Mar-21 5:41am    
 public void btn_abnrmalsixnine_Click(object sender, EventArgs e)
        {
            try
            {

                DataTable dt_temp = new DataTable();
                DataSet ds = (DataSet)ViewState["GridViewData"];
                //DataTable DT_Main = (DataTable)ViewState["GridViewData"];
                DataTable DT_Main = ds.Tables[0];
                dt_temp = DT_Main.Clone();
                //Button btnEdit = (Button)sender;
                //ASPxGridView Grow = (ASPxGridView)btnEdit.NamingContainer; 
                // Session["AttendanceDate"] = Grow.RowIn
               // int fouscindex = grv_NormalabnormalSummaryReport.FocusedRowIndex;

                //GridColumn column = grv_NormalabnormalSummaryReport.Columns.FirstOrDefault();

                Session["AttendanceDate"] = grv_NormalabnormalSummaryReport.GetRowValues(grv_NormalabnormalSummaryReport.FocusedRowIndex, "AttendanceDate").ToString();
                Session["organization"] = grv_NormalabnormalSummaryReport.GetRowValues(grv_NormalabnormalSummaryReport.FocusedRowIndex, "Orgname").ToString();
                Session["OrgId "] = grv_NormalabnormalSummaryReport.GetRowValues(grv_NormalabnormalSummaryReport.FocusedRowIndex, "OrgId").ToString();
                    string organization = Session["organization"].ToString();
                    string AttendanceDate = Session["AttendanceDate"].ToString();
                    int OrgId = Convert.ToInt32(Session["OrgId "].ToString());
                    //  ASPxGridView row = (ASPxGridView)grv_NormalabnormalSummaryReport.GetSelectedFieldValues();
                    dt_temp = DT_Main.AsEnumerable().Where(r => r.Field<DateTime>("AttendanceDate").ToString() == AttendanceDate
                                                      && r.Field<string>("AttendanceStatus").ToString() == "Abnormal" &&
                                                         r.Field<int>("TravelTime") >= 6 &&
                                                         r.Field<int>("TravelTime") <= 9).CopyToDataTable();

                    grv_EmployeeList.DataSource = dt_temp;
                    grv_EmployeeList.DataBind();
                    grv_details.Text = organization.ToString();
                    popupEmployeeList.ShowOnPageLoad = true;
                    return;
            
               
            //Get Current GridView Row Attendance Date...

            //Session["AttendanceDate"] = (this.grv_NormalabnormalSummaryReport.GetRowValues(i, "id").ToString());

           
             
            }
            catch
            {

            }
        }


I am getting Same issue Please help

1 solution

C#
if (dtTemSec.Rows.Count > 0)
                    {

                        var table = dtTemSec;
                        var rows = table.AsEnumerable().Where(x => x.Field<string>("Status") != "D" && x.Field<string>("ID") == "ST" && x.Field<int>("Folder") == folder);
                        var dt = rows.Any() ? rows.CopyToDataTable() : table.Clone();
                         grdStepDetails.DataSource =dt;
                         grdStepDetails.DataBind();
                        ClientScript.RegisterStartupScript(GetType(), "Val", "ShowStepPopup();", true);


                    }
                    else
                    {
                        grdStepDetails.DataSource = null;
                        grdStepDetails.DataBind();
                        ClientScript.RegisterStartupScript(GetType(), "Val", "ShowStepPopup();", true);
                    }
 
Share this answer
 
Comments
Code For You 31-Mar-15 7:24am    
which type of object is "dtTemSec" .?
jithesh a 17-Apr-15 5:19am    
its temporary datatable in my code

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