可空对象必须具有值C#Syncfusion

尝试在asp .net上实施甘特图时遇到此错误。

我已经添加了我的方法,它正在调试模式下运行,并且也没有提供任何信息。

这是我的隐藏代码;我正在使用存储过程,并且无法使用代码中的直接SQL查询。

我想做的是从数据库中调用方法(SP),以便进行CRUD操作。目前,我有这个,但是它没有渲染任何信息。

    using DSProyectosTableAdapters;
    using DSInformesProyectosTableAdapters;
    using Syncfusion.JavaScript.DataVisualization.Models;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Data.SqlClient;
    using System.Linq;
    using system.web.Services;
    using system.web.UI;
    using system.web.UI.WebControls;

    public partial class ListarClientesProyectoGantt : clsUsuario
    {
        protected int idPagina = 1;
        protected string sConfSing = "Grafica Gantt";
        protected string sConfPlu = "Graficas Gantt";

        public int? Proyecto
        {
            get
            {
                int? id = null;
                int idAux;
                if (ViewState["idProyecto"] != null && ViewState["idProyecto"].ToString() != "" && int.TryParse(Request.QueryString["P"].ToString(),out idAux))
                    id = idAux;
                else
                {
                    if (Request.QueryString.HasKeys() && Request.QueryString["P"] != null && Request.QueryString["P"].ToString() != "" && int.TryParse(Request.QueryString["P"].ToString(),out idAux))
                    {
                        id = idAux;
                        this.Proyecto = id;
                    }
                    else if (Request.UrlReferrer != null)
                    {
                        if (Request.UrlReferrer.AbsolutePath != Request.Url.AbsolutePath && Request.UrlReferrer.Query != "")
                        {
                            Response.Redirect(string.Format("{0}{1}",Request.Url.AbsolutePath,Request.UrlReferrer.Query));
                        }
                    }
                }
                return id;
            }
            set
            {
                this.ViewState["idProyecto"] = value;
            }
        }

        protected void Page_Init(object sender,EventArgs e)
        {
            try
            {
                if (!this.Proyecto.HasValue)
                {
                       //     Response.Redirect("~/PnlCliente/ListarClientesProyectoGantt.aspx");
                }
            }
            catch (System.Threading.threadabortexception)
            {
                Response.End();
            }
            catch (Exception TrackViewState )
            {
                msj.MostrarMensaje(3,TrackViewState.Message,TrackViewState );
            }
        }

        protected void Page_Load(object sender,EventArgs e)
        {
            try
            {
                msj.Visible = false;

                var MasterP = (Layout2)this.Master;
                MasterP.ConstruirMenu(idPagina,(int)Proyecto.Value,4);

                this.GanttControl.DataSource = GetGanttData();
                this.GanttControl.DataBind();
            }
            catch (Exception TrackViewState)
            {
                msj.MostrarMensaje(2,TrackViewState);
            }
        }

        public class actividadesInfo
        {


            public string TaskId { get; set; }
            public string TaskName { get; set; }
            public DateTime StartDate { get; set; }
            public DateTime EndDate { get; set; }
            public string ParentId { get; set; }
            public string Duration { get; set; }
            public string Progress { get; set; }
            public string Predecessor { get; set; }

        }

        public List<actividadesInfo> GetGanttData()

        {

         sp_GanttTableAdapter DatosTA = new sp_GanttTableAdapter();

         DSProyectos.sp_GanttDataTable DatosT = DatosTA.GetDataIdProyecto(Proyecto);

            List<actividadesInfo> list = new List<actividadesInfo>();
            foreach (var DatosR in DatosT)
            {
            list.Add(new actividadesInfo() { TaskId = DatosR.id.ToString(),ParentId =(DatosR.IsidPadreNull() ? 0 : DatosR.idPadre).ToString(),EndDate = DatosR.IsdFechaFNull() ? DateTime.Now : DatosR.dFechaF,StartDate = DatosR.IsdFechaINull() ? DateTime.Now : DatosR.dFechaI,Duration = "3",Predecessor = null,Progress = "100",TaskName = DatosR.sTitulo });

            }

            return list;
        }


    }


<%@ Page Language="C#" EnableEventValidation="false" MasterPageFile="~/PnlCliente/Layout2.master" AutoEventWireup="true" EnableTheming="false" CodeFile="ListarClientesProyectoGantt.aspx.cs" Inherits="ListarClientesProyectoGantt" %>

<asp:Content ID="Content3" ContentPlaceHolderID="cphFiltro" runat="Server">
    <bit:mensajesv3 ID="msj" runat="server" />
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="cphHead" runat="Server">
    <link href="../App_Themes/samva/assets/syncfusion/Content/ejthemes/ej.widgets.core.min.css" rel="stylesheet" />
    <link href="../App_Themes/samva/assets/syncfusion/Content/ejthemes/material/ej.theme.min.css" rel="stylesheet" />

    <script src="../App_Themes/samva/assets/syncfusion/Scripts/ej/web/ej.web.all.min.js"></script>
    <script src="../App_Themes/samva/assets/syncfusion/Scripts/jsviews.min.js"></script>
    <script src="../App_Themes/samva/assets/syncfusion/Scripts/jsrender.min.js"></script>
    <script src="../App_Themes/samva/assets/syncfusion/Scripts/jquery.easing-1.3.min.js"></script>
            <script type="text/javascript">            

            function actionComplete(args) {

                if (args.requestType == "indent" || args.requestType == "outdent" || args.requestType == "recordUpdate" || (args.requestType === 'save' && args.modifiedRecord) || args.requestType == "drawConnectorLine") {
                    var ganttRec = [];

                    if (args.requestType == "save")
                        ganttRec.push(args.modifiedRecord);
                    else if (args.requestType == "drawConnectorLine")
                        ganttRec.push(args.currentRecord);
                    else
                        ganttRec.push(args.data); 
                    if (args.updatedRecords && args.updatedRecords.length)
                        ganttRec = ganttRec.concat(args.updatedRecords);
                    updateModifiedGanttRecords(ganttRec);
                }

                else if (args.requestType == "save" && args.addedRecord) {
                    var data = args.addedRecord.item;
                    PageMethods.AddIt(data);


                    if (args.updatedRecords && args.updatedRecords.length)
                        updateModifiedGanttRecords(args.updatedRecords);
                }
                else if (args.requestType == "dragAndDrop") {
                    var ganttRec = [];
                    ganttRec.push(args.draggedRow);
                    if (args.updatedRecords && args.updatedRecords.length)
                        ganttRec = ganttRec.concat(args.updatedRecords);
                    updateModifiedGanttRecords(ganttRec);
                }


                else if (args.requestType == "delete") {
                    var data = args.data.item;
                    PageMethods.DeleteIt(data);
                    if (args.data.hasChildRecords) {
                        deleteChildRecords(args.data);
                    }
                    if (args.updatedRecords && args.updatedRecords.length)
                        updateModifiedGanttRecords(args.updatedRecords);
                }
            }

            function updateModifiedGanttRecords(records) {
                var modifiedRecord = [];
                if (records && records.length) {
                    var length = records.length;
                    for (var i = 0; i < length; i++)
                        modifiedRecord.push(records[i].item);
                }
                PageMethods.UpdateIt(modifiedRecord);
            }


            function deleteChildRecords(record) {
                var childRecords = record.childRecords,length = childRecords.length,count,currentRecord;
                for (count = 0; count < length; count++) {
                    currentRecord = childRecords[count];
                    var data = currentRecord.item;
                    PageMethods.DeleteIt(data);
                    if (currentRecord.hasChildRecords) {
                        deleteChildRecords(currentRecord);
                    }
                }
            }



        </script>
    </asp:Content>


这是我的.aspx。我不知道我是否在aspx文件中正确映射了所有必要字段。

任何建议或帮助将不胜感激。预先感谢。


    <asp:Content ID="Content1" ContentPlaceHolderID="cphContenido" runat="Server">

        <ej:Gantt ID="GanttControl" runat="server" AllowSelection="True" DateFormat="M/dd/yyyy"
                TaskNameMapping="TaskName" StartDateMapping="StartDate" AllowDragAndDrop="true"
                EndDateMapping="EndDate" ProgressMapping="Progress" ParentTaskIdMapping="ParentId" Durationmapping="Duration"
                ScheduleStartDate="01/26/2019" ScheduleEndDate="03/20/2019" PredecessorMapping="Predecessor"
                TreeColumnIndex="1" AllowGanttChartEditing="true" actionComplete="actionComplete" EnableContextMenu="true">
                <dragtooltip showtooltip="true" />
       <editsettings allowediting="true" allowadding="true" allowdeleting="true" allowindent="true" editmode="normal" rowposition="Child"  />
       </ej:Gantt>



    </asp:Content>

This is the line where is ocurring the breakpoint

dongzh00 回答:可空对象必须具有值C#Syncfusion

我们检查了您共享的代码段。并且我们注意到,id(null)值分配给Proyecto。在Page_Init方法中,检查了this.Proyecto.HasValue条件。我们不能盲目检查可为空的变量的HasValue。请继续检查空条件。

public int? Proyecto
    {
        get
        {
           int? id = null;
             //...
            else
            {
             //... 
               {
           this.Proyecto = id;
                }
                //...
            }
            return id;
        }

    }

    protected void Page_Init(object sender,EventArgs e)
    {
        try
        {
            if (!this.Proyecto.HasValue)
            {
                //     
            }
        }
   //...
    }
本文链接:https://www.f2er.com/3150260.html

大家都在问