Click here to Skip to main content
15,911,646 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i try to get report when user click on update.. scenario is there is edit button in gridview and also there is several records so when user click on this edit button then box appear furthermore there is several fields then user select report type from drop down now when user select report type and click on update button then report is display but when i debug error is occurred

What I have tried:

i try this code

C#
protected void gvNR_NRListDevx_AfterPerformCallback(object sender, ASPxGridViewAfterPerformCallbackEventArgs e)
        {
            if (e.CallbackName == "STARTEDIT")
            {
                int index = ((ASPxGridView)sender).EditingRowVisibleIndex;
                //view state value with in page... in this code we get form id from gridview
                ViewState["FFID"] = ((ASPxGridView)sender).GetRowValues(((ASPxGridView)sender).FocusedRowIndex, "FormID");
                //get vechile id from gridview
                ViewState["VID"] = ((ASPxGridView)sender).GetRowValues(((ASPxGridView)sender).FocusedRowIndex, "VID");
                //get form datetime from gridview
                ViewState["DateTime"] = Convert.ToDateTime(((ASPxGridView)sender).GetRowValues(((ASPxGridView)sender).FocusedRowIndex, "DateTime"));


            }
            else if (e.CallbackName == "CANCELEDIT")
            {

            }
            else if(e.CallbackName == "UPDATEEDIT")
            {
                DateTime DateT = (DateTime)ViewState["DateTime"];
                string VehId = (string)ViewState["VID"];
                _sys = new clsDe_ComplainMaster();
                DataTable dtUpdated = _sys.SelectUpdatedNRtype(ViewState["FFID"].ToString(), VehId, DateT);

                if (dtUpdated.Rows[0]["NRType"].ToString() == "0002") 
                {
                    printgpsreport(DateT, VehId, "REPORT1.rpt");
                }
                else if (dtUpdated.Rows[0]["NRType"].ToString() == "0011")
                {
                    printgpsreport(DateT, VehId, "REPORT2.rpt");
                }



 public DataTable SelectUpdatedNRtype(string FormID , string VEhID, DateTime DateT)
    {
        string strSql = "select NRType from NR_NRType_LogHistory where FormID = '" + FormID + "' ANd VehicleID = '" + VEhID + "' AND NRDate = '" + DateT + "'";

        return this.GetQueryData(strSql);

    }

public DataSet getreport()
    {
        DataSet ds;
        try
        {
            SqlParameter[] Params = 
            { 
                new SqlParameter("@datetime",SqlDbType.DateTime),
                new SqlParameter("@VehID",SqlDbType.VarChar)

        };

            if ( datetime != null)
            {
                Params[0].Value = datetime;

            }
            else
            {
                Params[0].Value = DBNull.Value;
            }

            if (VehID != null)
            {
                Params[1].Value = VehID;
            }
            else
            {
                Params[1].Value = DBNull.Value;
            }

            ds = GetDataSet("sp_gps_report", Params);

            return ds;
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }

    }

ERROR IS OCCURRED ON THIS LINE

DateTime DateT = (DateTime)ViewState["DateTime"];
An exception of type 'System.NullReferenceException' occurred in ERP.dll but was not handled in user code

Additional information: Object reference not set to an instance of an object.

any help please
Posted
Updated 28-Apr-16 1:24am
Comments

1 solution

C#
An exception of type 'System.NullReferenceException' occurred in ERP.dll but was not handled in user code
Simple, ViewState["DateTime"] is null. Make sure you have value in the ViewState property before accessing it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900