[英]C# Show selected row data in a new gridview 1-1 relationship
我正在創建一個簡單的患者應用程序。 1-1 患者與病史記錄的關系。 當應用程序啟動時,會顯示患者。 選擇一名患者並單擊按鈕時,應顯示該患者的病史。
我的問題是所有病史都被顯示,而不是那個特定的病人。
private void PopulateGrid()
{
var records = _db.GeneralMedicalHistories.Select(q => new
{
PatientNumber = q.GeneralMedicalHistoryID,
MaritalStatus = q.MartialStatus,
Education = q.Education,
BloodType = q.BloodType,
Pregenancies = q.Pregnancies,
Tobacco = q.Tobacco,
Alcohol = q.Alcohol,
Drug = q.Drug,
MedicalHistoryNotes = q.MedicalHistoryNotes,
}).ToList();
gvDemographics.DataSource = records;
gvDemographics.Columns["PatientNumber"].HeaderText = "Patient#";
gvDemographics.Columns["MaritalStatus"].HeaderText = "Marital Status";
gvDemographics.Columns["BloodType"].HeaderText = "Blood Type";
gvDemographics.Columns["MedicalHistoryNotes"].HeaderText = "Medical History Notes";
//Hide the column for ID. Changed from the hard coded column value to the name,
// to make it more dynamic.
gvDemographics.Columns["PatientNumber"].Visible = true;
}
您已選擇要在 gridview 中顯示的元素,但您尚未設置任何類型的標准來過濾查詢結果。 為此,首先獲取與您要顯示的記錄關聯的 ID,我將其命名為patientID
。 將.Where(PatientNumber = patientID)
擴展方法添加到您的查詢應該將您的結果過濾到僅具有該patientID
的患者。
.Where()
文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.