title: How to Add DataTable value in DataSet Using every foreach loop in ASP.NET C# Webform
body: <p>How to Add DataTable value in DataSet Using every foreach loop in ASP.NET C# Webform, Actually I have one gridview and in gridview selected checkbox data should only download to xl.</p>
  
  <p>I have below code for export to xl button.</p>
  
  <pre><code>     foreach (GridViewRow row in gv_TotalAllReg.Rows)
          {
              if (row.RowType == DataControlRowType.DataRow)
              {
                  bool isChecked = ((CheckBox)row.FindControl("chk_box")).Checked;
                  if (isChecked == true)
                  {
                      //var ds = new DataSet();
                      //var dt = new DataTable("RegistrationDetails");
  
                      int index = row.RowIndex;
  
                      bo.Para1 = "4";
                      bo.Para2 = "Innovation";
  
                      bo.Para3 = gv_TotalAllReg.DataKeys[index].Values[0].ToString();//Id
  
  
  
                  }
              }
          }
          dt = bl.Admin_GetInnovationbaseonParaType(bo);
          if (gv_TotalAllReg.Rows.Count &gt; 0)
          {
              dt.TableName = "RegistrationDetails";
              ds.Tables.Add(dt);
              ExcelHelper.ToExcel(ds, "ApplicationDetails.xls", Page.Response);
              btnExport.Visible = true;
  
  
          }
  </code></pre>
  
  <p>Actually base on selected checkbox in gridview that data is not showing in xl sheet, only last selected data is showing in xl sheet. </p>
  
  <p>I am not getting logic <code>ds.Tables.Add(dt);</code> to add <code>dt</code> values in ds every foreach loop. I need all selected data into xl sheet. Why last select data only coming in xl sheet. </p>