Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

delete empty rows in datatable c# ASP.NET



public DataTable DeleteEmptyRows(DataTable dt)
    {
        DataTable formattedTable = dt.Copy();
        List<DataRow> drList = new List<DataRow>();
        foreach (DataRow dr in formattedTable.Rows)
        {
            int count = dr.ItemArray.Length;
            int nullcounter = 0;
            for (int i = 0; i < dr.ItemArray.Length; i++)
            {
                if (dr.ItemArray[i] == null || string.IsNullOrEmpty(Convert.ToString(dr.ItemArray[i])))
                {
                    nullcounter++;
                }
            }

            if (nullcounter == count)
            {
                drList.Add(dr);
            }
        }

        for (int i = 0; i < drList.Count; i++)
        {
            formattedTable.Rows.Remove(drList[i]);
        }
        formattedTable.AcceptChanges();

        return formattedTable;
    }


This post first appeared on Asp.netSourceCodes, please read the originial post: here

Share the post

delete empty rows in datatable c# ASP.NET

×

Subscribe to Asp.netsourcecodes

Get updates delivered right to your inbox!

Thank you for your subscription

×