title: Passing Selected Row data using EventArgs e
body: <p>Can someone help me with my GridView <code>EventHandler</code> problem? I have this GridView that has a button for each row that will extract data to excel using the <code>ID</code> as filter to my LINQ.</p>
  
  <p>My problem is that how will I do it using the only two parameter present on the method of the <code>EventHandler</code>?</p>
  
  <pre><code>protected void gvJobs_RowCommand(Object sender, GridViewCommandEventArgs e)
  {
      if (e.CommandName == "btnExtract_Click")
      {                                                                
           int index = Convert.ToInt32(e.CommandArgument);
           GridViewRow row = gvJobs.Rows[index];
  
           //EventHandler call
           ExtractJobsCalibrationForm(sender, e);
      }                                                                
  }
  </code></pre>
  
  <p>It triggers the event but I'd like to know if how the data for a specific row button that was click will pass the ID of that selected row to the <code>EventHandler</code>.</p>
  
  <p>Here is my code for the <code>EventHandler</code>:</p>
  
  <pre><code>void View_ExtractJobsCalibrationForm(object sender, EventArgs e) 
  {
      try
      {
          using (Data.DataContexts.IDataContext objContext = Data.DataContexts.DataContext.CreateDataContext()) 
          {
              IQueryable&lt;Data.JobSummary&gt; objJobs = objContext.Jobs.GetJobSummaries().Where(j =&gt; !j.IsDeleted);
  
              string path = HttpContext.Current.Server.MapPath("/Reports/ExcelTemplate/Calibration_Form_ARS-FORM-CL1_Template.xlsx");
              string destPath = @"C:\Users\ringgo_dejesus\Desktop\Calibration_Form_ARS-FORM-CL1_Template.xlsx";
  
  
              oXL = new Microsoft.Office.Interop.Excel.Application();
              oXL.Visible = true;
              oXL.DisplayAlerts = false;
  
              //Create a copy from the Template to save the data.
              System.IO.File.Copy(path, destPath, true);
  
              //Open the copied template.
              mWorkBook = oXL.Workbooks.Open(destPath, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
  
              //Get all the sheets in the workbook
              mWorkSheets = mWorkBook.Worksheets;
              //Get the allready exists sheet
              mWSheet = (Microsoft.Office.Interop.Excel.Worksheet)mWorkSheets.get_Item("Pre calibration Check in");
  
              //Microsoft.Office.Interop.Excel.Range range = mWSheet.UsedRange;
              //int colCount = range.Columns.Count;
              //int rowCount = range.Rows.Count;
  
              //for (int index = 1; index &lt; 15; index++)
              //{
              //    mWSheet.Cells[rowCount + index, 1] = rowCount + index;
              //    mWSheet.Cells[rowCount + index, 2] = "New Item" + index;
              //}
  
              Excel.Range JobNo = (Excel.Range)mWSheet.Rows.Cells[2, 2];
              Excel.Range Date = (Excel.Range)mWSheet.Rows.Cells[3, 2];
              Excel.Range CheckedInBy = (Excel.Range)mWSheet.Rows.Cells[4, 2];
              Excel.Range ClientName = (Excel.Range)mWSheet.Rows.Cells[7, 2];
              Excel.Range ClientNum = (Excel.Range)mWSheet.Rows.Cells[8, 2];
              Excel.Range PONumber = (Excel.Range)mWSheet.Rows.Cells[9, 2];
              Excel.Range MonitorManufacturer = (Excel.Range)mWSheet.Rows.Cells[22, 4];
              Excel.Range MonitorModel = (Excel.Range)mWSheet.Rows.Cells[23, 4];
              Excel.Range MonitorSerialNum = (Excel.Range)mWSheet.Rows.Cells[24, 4];
              Excel.Range ProbeManufacturer = (Excel.Range)mWSheet.Rows.Cells[26, 4];
              Excel.Range ProbeModel = (Excel.Range)mWSheet.Rows.Cells[27, 4];
              Excel.Range ProbeSerialNum = (Excel.Range)mWSheet.Rows.Cells[28, 4];
              Excel.Range LastCalibrated = (Excel.Range)mWSheet.Rows.Cells[37, 4];
  
              var data = objJobs.Where(j =&gt; j.JobReference.Contains(View.JobReferenceNo.Trim()))
                                .Select(x =&gt; new
                                {
                                    JobNum = x.JobReference,
                                    CreationDate = x.DateCreated,
                                    CreatedBy = x.CreatedByUserId,
                                    ClientName = x.ClientName,
                                    ClientNumber = x.ClientId,
                                    PONumber = x.PurchaseOrderNumber
                                }).FirstOrDefault();
  
              JobNo.Value = data.JobNum;
              Date.Value = data.CreationDate;
              CheckedInBy.Value = data.CreatedBy;
              ClientName.Value = data.ClientName;
              ClientNum.Value = data.ClientNumber;
              PONumber.Value = data.PONumber;
  
              mWorkBook.Save();
              //mWorkBook.SaveAs(path, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
  
              //mWorkBook.Close(Missing.Value, Missing.Value, Missing.Value);
              mWSheet = null;
              mWorkBook = null;
              //oXL.Quit();
              GC.WaitForPendingFinalizers();
              GC.Collect();
              GC.WaitForPendingFinalizers();
              GC.Collect();
          }
      }
      catch (Exception objException)
      {
          View.DisplayException(objException);
      }
  }
  </code></pre>
  
  <p>And I'd like to use the selected row number or Id to filter my LINQ for <code>objJobs</code>.</p>