GridView EventHandler
の問題を教えてもらえますか?私はこのグリッドビューには、LINQのフィルタとしてID
を使用してExcelにデータを抽出する各行のボタンがあります。EventArgs eを使用して選択した行データを渡す
私の問題は、EventHandler
のメソッドに存在する唯一の2つのパラメータを使用して、どうやって行うのでしょうか?
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);
}
}
これは、イベントをトリガしますが、私は、クリックした特定の行のボタンのどのデータがEventHandler
にその選択された行のIDを渡しますかどうかを知りたいのです。
はここにEventHandler
のために私のコードです:
void View_ExtractJobsCalibrationForm(object sender, EventArgs e)
{
try
{
using (Data.DataContexts.IDataContext objContext = Data.DataContexts.DataContext.CreateDataContext())
{
IQueryable<Data.JobSummary> objJobs = objContext.Jobs.GetJobSummaries().Where(j => !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 < 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 => j.JobReference.Contains(View.JobReferenceNo.Trim()))
.Select(x => 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);
}
}
そして私はobjJobs
のための私のLINQをフィルタするために選択された行番号またはIDを使用したいと思います。