title: Persist information in DataTable
body: <p>I have datatable which is bound to a Gridview on page to show data.
  then I have a Add new button which opens up a Usercontrol in a Bootstrap Modal.
  This Addnew usercontrol needs to have a form to enter the details</p>
  
  <p>ID
  Address
  State
  City
  Country</p>
  
  <p>These details are added to the datatable .</p>
  
  <p>Right now there is no database involved.</p>
  
  <p>DataTable is initiated then few string type columns are added to it then rows are added , all this in Pageload of Webform than there is a AddNew button which opens a UserControl in this UserControl there are labels and Textboxes and a add button , I need to Add a row in the Datatable initiated in the Webform in this Usercontrol.</p>
  
  <p>Following is the code on the Webform</p>
  
  <pre><code>   protected void Page_Load(object sender, EventArgs e)
     {
     //if (!IsPostBack)
     //{
       DataTable mytestdata = new DataTable();
       Session["DataTable"] = mytestdata;
  
       if (mytestdata.Columns.Count == 0)
       {
         mytestdata.Columns.Add("ID", typeof(string));
         mytestdata.Columns.Add("Address 1", typeof(string));
         mytestdata.Columns.Add("Street", typeof(string));
         mytestdata.Columns.Add("City", typeof(string));
         mytestdata.Columns.Add("Post Code", typeof(string));
         mytestdata.Columns.Add("Country", typeof(string));
        }
  
       if (mytestdata.Rows.Count == 0)
       {
         mytestdata.Rows.Add("1341", "Number 49", "Phibsboro", "Dublin 2",             
         "11111", "Ireland");
         mytestdata.Rows.Add("1241", "Number 46", "Dundrum", "Dublin 6",    
         "124354", "uk");
         mytestdata.Rows.Add("1351", "Number 43", "Phibsboro", "Dublin 7",  
         "23445", "Ireland");
         mytestdata.Rows.Add("1141", "Number 59", "Dundrum", "Dublin 8",  
         "11111", "uk");
         mytestdata.Rows.Add("1234", "Number 69", "Dundrum", "Dublin 9",  
         "23432", "Ireland");
         mytestdata.Rows.Add("1234", "Number 29", "Phibsboro", "Dublin 10",  
         "11111", "uk");
         mytestdata.Rows.Add("4312", "Number 52", "Dundrum", "Dublin 18",     
         "23422", "Ireland");
  
         mytestdata.Rows.Add("5467", "Number 19", "Dundrum", "Dublin 19",  
        "11111", "Ireland");
         mytestdata.Rows.Add("4352", "Number 21", "Phibsboro", "Dublin 24",  
         "125632", "uk");
         mytestdata.Rows.Add("6543", "Number 15", "Dundrum", "Dublin 19",   
         "11111", "Ireland");
         mytestdata.Rows.Add("5785", "Number 24", "Phibsboro", "Dublin 12",   
         "11111", "uk");
       }
  
       mytestdata = (DataTable)Session["DataTable"];
       ucModalCrud._dtCRUD = mytestdata;
  
       ucModalCrud._pathToAddViewRecordUserControl =                             "~/PortalFramework/Shared/ModalCRUD/ForTesting/ucViewRecordDetails.ascx";
  </code></pre>
  
  <p>ucModalCrud._pathToAddNewRecordUserControl = "~/PortalFramework/Shared/ModalCRUD/ForTesting/ucAddDetails.ascx";</p>
  
  <pre><code>//}
  </code></pre>
  
  <p>}</p>
  
  <p>Following is the code in the usercontrol</p>
  
  <pre><code>   protected void btnAdd_Click(object sender, EventArgs e){
  
      DataTable mytestdata = new DataTable();
      mytestdata = (DataTable)Session["DataTable"];
  
      mytestdata.Rows.Add(txtID.Text, txtAddress1.Text, txtStreet.Text,    
      txtCity.Text, txtPostCode.Text, txtCountry.Text);
      Session["DataTable"] = mytestdata;
  
     }
  </code></pre>
  
  <p>I need a way to persist the same DataTable throughout the website</p>