public static bool SearchRows(string strCol, string strCriteria)
    {
        /// Table_Values.SearchRows(myCol, strTxtSearch);
        // 0 = Item col1
        // 1 = Description col2
        // 2 = price  col3
        Demo_row.Clear();
        GlobalClass.Master_NumberOfRows = 0;

            XmlDocument xmldoc = new XmlDocument();
            try
            {
                GetXMLdoc apt = new GetXMLdoc();
                xmldoc = apt.OpenAppXMLFile();
            }
            catch (Exception ex)
            {
                GlobalClass.ErrorMessage = "Error in SearchRows in calling GetXMLdoc: " + ex.Message;
            }

            XmlNode ele = xmldoc.DocumentElement;
            XmlNodeList cldnode = ele.ChildNodes;

            foreach (XmlNode xn in cldnode)
            {
              // For demo purposes we're just doing any exact match.
              // In the future we could use Reg Expressions

                if (xn[strCol].InnerText == strCriteria)
                {

                    try
                    {
                        Demo_row.Add(new Grid_Row_Values
                            (GlobalClass.Master_NumberOfRows++, xn["col0"].InnerText, xn["col1"].InnerText, xn["col2"].InnerText, Convert.ToDouble(xn["col3"].InnerText), null));
                    }
                    catch (Exception e)
                    {
                        GlobalClass.ErrorMessage = "Error in Table_Values.cs (SearchRows(str,str): Error Message:" + e.Message;
                        return false;
                    }
                }

            }

        return true;
    }
    public static bool BuildList()
    {
        GlobalClass.Master_NumberOfRows = 0;    // Probably not necessary
        int i = 0;
        int j = 0;
        string cellName = "";

        XmlDocument xmldoc = new XmlDocument();

        try
        {

            GetXMLdoc apt = new GetXMLdoc();
            xmldoc = apt.OpenAppXMLFile();
        }
        catch (Exception ex)
        {
            GlobalClass.ErrorMessage = "Error in BuildList in calling GetXMLdoc: " + ex.Message;
        }

        if (xmldoc.DocumentElement != null)
        {
            XmlElement element = xmldoc.DocumentElement;
            XmlNodeList lstcols = element.ChildNodes;
            cellName = string.Empty;

            if (lstcols.Count == 0)
            {
                GlobalClass.ErrorMessage = string.Empty;
                return false;
            }

            for (i = 0; i < lstcols.Count; i++)
            {

                cellName = "col" + (j + 1);

                try
                {
                    InsertXMLRowsIntoList(GlobalClass.Master_NumberOfRows++,
                        Convert.ToString(lstcols[i]["col0"].InnerText),
                        Convert.ToString(lstcols[i]["col1"].InnerText),
                        Convert.ToString(lstcols[i]["col2"].InnerText),
                        Convert.ToDouble(lstcols[i]["col3"].InnerText));
                }

                catch (Exception ex)
                {

                    GlobalClass.ErrorMessage = ex.Message + ex.Source;
                    return false;

                }

            }
        }

        //GlobalClass.GetXMLDoc = null;

        return true;
    }
    protected void btnPort_click(object sender, EventArgs e)
    {
        // Wished I could ReaderWriterLockSlim here

        this.txtNumberOfEntries.Text = null;

        if (Table_Values.DemoList.Count < 1)
        {
            this.lblRowError.Text = "No data rows.";
            return;
        }

        foreach (Grid_Row_Values grv in Table_Values.DemoList)
        {
            if (grv.colItem == null || grv.colDescription == null || grv.colIdentifier == null  )
            {
                this.lblRowError.Text = "Can't submit incomplete data to the Item XML file.";
                return;
            }
        }

        bool xmlDocChanged = false;
        int my_increment = 0;
        string myStatus = string.Empty;
        string App_Path = @ConfigurationManager.AppSettings["Data_Path"].ToString();
        App_Path = App_Path + "Items.xml";
        XmlNodeList cldnode;
        string[] arrayDelete;

            XmlDocument xmldoc = new XmlDocument();
            try
            {

                 GetXMLdoc apt = new GetXMLdoc();
                 xmldoc = apt.OpenAppXMLFile();
            }
            catch (Exception ex)
            {
                GlobalClass.ErrorMessage = "Error in btnPort_click: " + ex.Message;
                Response.Redirect("ErrorMessage.aspx");
            }

            XmlNode ele = xmldoc.DocumentElement;
            cldnode = ele.ChildNodes;
            arrayDelete = new string[cldnode.Count];

            for (my_increment = 0; my_increment < cldnode.Count; my_increment++)
            {
                arrayDelete[my_increment] = null;
            }

            my_increment = 0;
            foreach(Grid_Row_Values grv in Table_Values.DemoList)
            {

               myStatus = grv.colStatus;

               if (myStatus == "changed")
               {

                       xmlDocChanged = true;
                       // Have to create a new node first
                       XmlElement top = xmldoc.CreateElement("items");
                       XmlElement child0 = xmldoc.CreateElement("col0");
                       XmlElement chi1d1 = xmldoc.CreateElement("col1");
                       XmlElement child2 = xmldoc.CreateElement("col2");
                       XmlElement child3 = xmldoc.CreateElement("col3");
                       child0.InnerText = Convert.ToString(grv.colIdentifier);
                       chi1d1.InnerText = grv.colItem;
                       child2.InnerText = grv.colDescription;
                       child3.InnerText = Convert.ToString(grv.colPrice);
                       top.AppendChild(child0);
                       top.AppendChild(chi1d1);
                       top.AppendChild(child2);
                       top.AppendChild(child3);
                       ele.AppendChild(top);
                       ele.ReplaceChild(top, cldnode[my_increment]);
                       my_increment++;

               }
            }   // end change foreach

               if (xmlDocChanged)
               {
                   xmldoc.Save(@App_Path);    // the childnode count hasn't changed
                   xmlDocChanged = false;
               }

           my_increment = 0;
          // Delete from XML
          foreach(Grid_Row_Values grv in Table_Values.DemoList)
          {
              // Insert code to check for duplicates
              myStatus = grv.colStatus;

             if (myStatus == "deleted")
              {
                // Build "innerText" from grv
                arrayDelete[my_increment++] = grv.colIdentifier+grv.colItem+grv.colDescription+grv.colPrice;
             }

          }
            my_increment = 0;

            // Check the array first becuase it is likely to have fewer elemtns
            // then Childnodes
            for (int ii = 0; ii < arrayDelete.Length; ii++)
            {
                if (arrayDelete[ii] != null)
                {
                    foreach (XmlNode xn in xmldoc.DocumentElement.ChildNodes)
                    {

                        if (xn.InnerText == arrayDelete[ii])
                        {
                            xmldoc.DocumentElement.RemoveChild(xn);
                            xmlDocChanged = true;
                        }
                    }
                }

            }

           // Save to XML
          if (xmlDocChanged)
          {
              xmldoc.Save(@App_Path);    // the childnode count HAS changed
              xmlDocChanged = false;
          }

          foreach (Grid_Row_Values grv in Table_Values.DemoList)
          {
              // Insert code to check for duplicates
              myStatus = grv.colStatus;

              if (myStatus == "new")
              {

                  xmlDocChanged = true;
                  XmlElement top = xmldoc.CreateElement("items");
                  XmlElement child0 = xmldoc.CreateElement("col0");
                  XmlElement chi1d1 = xmldoc.CreateElement("col1");
                  XmlElement child2 = xmldoc.CreateElement("col2");
                  XmlElement child3 = xmldoc.CreateElement("col3");
                  child0.InnerText = grv.colIdentifier;
                  chi1d1.InnerText = grv.colItem;
                  child2.InnerText = grv.colDescription;
                  child3.InnerText = Convert.ToString(grv.colPrice);
                  top.AppendChild(child0);
                  top.AppendChild(chi1d1);
                  top.AppendChild(child2);
                  top.AppendChild(child3);
                  ele.AppendChild(top);
              }
          }   // end new foreach
          if (xmlDocChanged)
          {
              xmldoc.Save(@App_Path);
          }

          this.lblRowError.Text = "Finished porting";
          if (GlobalClass.okRedirect)
          {

              Table_Values.DeleteRowValues();  // To clear the existing values and reflect updates
              Response.Redirect("Default.aspx?function=port");  // To refresh the GridView, not super happy with this
              GlobalClass.okRedirect = true;
          }

           // }  //if file exists
        return;
    }