0

请在 default.aspx.cs 中找到以下行

ASPxGridView 网格 = gvPatient.FindDetailRowTemplateControl(index, "gvOrder") as ASPxGridView;

它没有得到 gvPatient 的详细信息行模板内的 gvOrder Aspxgridview。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ADLPRO2MODEL;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.ASPxEditors;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void gvOrder_BeforePerformDataSelect(object sender, EventArgs e)
    {
        Session["PatientNo"] = (sender as ASPxGridView).GetMasterRowKeyValue();
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        // string key = (string)gvPatient.GetMasterRowKeyValue();

        decimal key = (decimal)Session["PatientNo"];

        int index = gvPatient.FindVisibleIndexByKeyValue(key);

        ASPxGridView grid = gvPatient.FindDetailRowTemplateControl(index, "gvOrder") as ASPxGridView;
        ASPxMemo tbNote = gvPatient.FindControl("tbNote") as ASPxMemo;
        ASPxLabel lblMsg = gvPatient.FindControl("lblMsg") as ASPxLabel;

        int patientNo = Convert.ToInt32(grid.GetSelectedFieldValues("PAT_NUMBER")[index]);
        int orderKey = Convert.ToInt32(grid.GetSelectedFieldValues("ORDER_KEY")[index]);

        ADLPRO2ENTITIES context = new ADLPRO2ENTITIES();

        ORD_D_PHA_RECOMMEND obj = context.ORD_D_PHA_RECOMMEND.FirstOrDefault(i => i.ORDER_KEY == orderKey && i.PAT_NUMBER == patientNo);

        bool? b = null;

        if (obj != null)
        {
            obj.Cont = b;

            if (tbNote.Text.Trim() != string.Empty)
            {
                obj.Note = tbNote.Text.Trim();
            }
        }
        else
        {
            obj = new ORD_D_PHA_RECOMMEND();
            obj.Cont = b;
            if (tbNote.Text.Trim() != string.Empty)
            {
                obj.Note = tbNote.Text.Trim();
            }
            obj.ORDER_KEY = orderKey;
            obj.PAT_NUMBER = patientNo;
            context.AddToORD_D_PHA_RECOMMEND(obj);
        }
        context.SaveChanges();

        tbNote.Text = string.Empty;

        lblMsg.Text = "Saved";
    }

}
4

0 回答 0