簡體   English   中英

C# 在新的 gridview 1-1 關系中顯示選定的行數據

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM