We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Assign DataView to repeater control: error: Object reference not set to an instance of an object.

TransBind
TransBind asked
on
Medium Priority
310 Views
Last Modified: 2010-08-05
I get an error Object reference not set to an instance of an object. when I am tryining
assign DataView to a datasource of a repeater control like so:

BioEducation Educ = new BioEducation();
DataView DV = Educ.EducationData().DefaultView;
dlEducation.DataSource = DV;

error is at this line: dlEducation.DataSource = DV;

//dlEducation is a repeater control
//EducationData is a function that returns DataTable

this line Educ.EducationData(); returns data ... I checked it by assigning it to DataTable like so:
//DataTable dt = new DataTable();
//dt = Educ.EducationData();
and looping through it ...

THIS CODE IS INSIDE private void Page_Load()

what could be the cause of that error?
Comment
Watch Question

Elvio Lujan.Net Senior Developer
CERTIFIED EXPERT

Commented:
make a break point in the error line... and evaluate the "dlEducation" valor... an tell me is it have an nothing value

Author

Commented:
i made a break point ... it crashes at that line but when it get to that line I have these values
dlEducation      <undefined value>      System.Web.UI.WebControls.Repeater
DV      {System.Data.DataView}      System.Data.DataView

Elvio Lujan.Net Senior Developer
CERTIFIED EXPERT

Commented:
and how you are declaring the dlEducation repeater control?

Author

Commented:
for a value to be assigned to RepeaterControl dlEducation
it should pass this line ...
dlEducation.DataSource = DV;

it never does ... so dlEducation  has   <undefined value>

Author

Commented:
in a cs file like so:

protected System.Web.UI.WebControls.Repeater dlEducation;

in aspx file
<asp:Repeater id="dlEducation" onitemdatabound="dlEducation_ItemDataBound">
etc ...
Elvio Lujan.Net Senior Developer
CERTIFIED EXPERT

Commented:
can you try this?...

dlEducation = this.FindControl("dlEducation");
dlEducation.DataSource = DV;

Author

Commented:
I did what u suggested ...
dlEducation = (Repeater)this.FindControl("dlEducation");
dlEducation.DataSource = DV;

I get the same error System.NullReferenceException: Object reference not set to an instance of an object.
at the same line: dlEducation.DataSource = DV;
.Net Senior Developer
CERTIFIED EXPERT
Commented:
sure...

<asp:Repeater id="dlEducation" onitemdatabound="dlEducation_ItemDataBound" runat=server>

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
what an idiot i am ....
Elvio Lujan.Net Senior Developer
CERTIFIED EXPERT

Commented:
don't worry... i haven't see too :)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.