asp.net datagrid binding problem


J

John A. Fuqua

I am getting the following error when trying to set the datasource for
my datagrid control:

"Object reference not set to an instance of an object"


Here is the code:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebRegistration
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox txtAccount;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Panel Step1Panel;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Panel Step2Panel;
protected System.Web.UI.WebControls.TextBox txtCSA_ShipToPostalCode;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.DataGrid dgCustomers;
protected System.Web.UI.WebControls.Label Label2;


private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here


}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
iGoBusinessManager.EntityObjects.ObjectFactory theFactory =
new iGoBusinessManager.EntityObjects.ObjectFactory();
iGoBusinessManager.EntityObjects.Interfaces.ICustomerManager
theCustomerManager =
(iGoBusinessManager.EntityObjects.Interfaces.ICustomerManager)theFactory.getInstance("CustomerManager");
IList customerList =
theCustomerManager.FindbyExample(Step1Panel.Controls.GetEnumerator(),
"Locations");
dgCustomers.DataSource = customerList;
Step2Panel.Visible = true;
Step1Panel.Visible = false;

}


}
}
 
Ad

Advertisements

A

Abhijeet Dev

Can u please send the exception info .. which line of code exception
occurred at ?
 
J

John Fuqua

It is happening on this line:

dgCustomers.DataSource = customerList;


The previous line is ok and shows a count of 19:

IList customerList =
 
J

Juliet Choy

It is difficult to diagnosis your problem since your code of creating
the CustomerList is encapsulated in your CustomerManager.

What error message do you get?
 
S

Scott Allen

The dgCustomers reference may be null. I'd set a breakpoint on the
line to confirm. If this is true, the first place to check is in the
aspx to see if a DataGrid control exists with an ID of dgCustomers
(case sensitive match).

HTH,
 
Ad

Advertisements

A

Abhijeet Dev

Check for dgCustomers, if it is in the page and it has runat="server" on.
Thats all the cause of this kind of problem can be..

Abhijeet Dev
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top