Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I develop Master-Child form.
On child form, I put a DetailsView control.
I write a code at Page Load.
C#
DataTable dt = new DataTable();
dt = vm.Gridfill(vm);
if (dt.Rows.Count > 0)
{
    DetailsView1.DataSource = vm.Gridfill(vm);
    DetailsView1.DataBind();
}
else
{
    DetailsView1.ChangeMode(DetailsViewMode.Insert);
}

I got error...
C#
Server Error in '/' Application.
 Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
   AjaxControlToolkit.MaskedEditExtender.OnLoad(EventArgs e) +135
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Control.LoadRecursive() +131
   System.Web.UI.Control.AddedControl(Control control, Int32 index) +318
   System.Web.UI.ControlCollection.Add(Control child) +146
   System.Web.UI.WebControls.CellControlCollection.Add(Control child) +34
   System.Web.UI.ControlCollection.AddAt(Int32 index, Control child) +33
   System.Web.UI.WebControls.CellControlCollection.AddAt(Int32 index, Control child) +40
Posted
v2
Comments
Can you please debug and let us know on which line exactly it is throwing the Exception?
member 8888995 26-Sep-13 2:51am    
Hi ,
Can you plaese specify details about this 'vm.Gridfill(vm)'.

--
Thanks
dhiraj mane 26-Sep-13 3:24am    
that's my class object (VehicleMaster vm = new VehicleMaster()) in that code is
public DataTable TableFill1(string Query)
{
DataTable dt = new DataTable();
try
{
if (con.State != ConnectionState.Open)
{
con.Open();
}
SqlDataReader dr;
cmd = new SqlCommand(Query, con);
cmd.CommandType = CommandType.StoredProcedure;
dr = cmd.ExecuteReader();
dt.Load(dr);
}
catch (Exception)
{
throw;
}
return dt;
}

As you are using DataBind Controls, make sure you are checking IsPostBack Property[^] on Page_Load.
C#
private void Page_Load()
{
    if (!IsPostBack)
    {
        // All your Binding codes here.
    }
}
 
Share this answer
 
Hi,

Make sure your code is not returning Null Value from this code "vm.Gridfill(vm);".
 
Share this answer
 
Hi Mr. Mane ,
what is type of vm that you are passing as argument to this method. It seems incorrect that you are invoking this method as vm.Gridfill() and passing vm as argument to it? The method that you illustrated here 'TableFill1()' takes string type argument. This is not correct and it's confusing.

--
Thanks
 
Share this answer
 
Comments
dhiraj mane 26-Sep-13 5:49am    
That problem is solve

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