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

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?
LVL 7
TransBindAsked:
Who is Participating?
 
Elvio Lujan.Net Senior DeveloperCommented:
sure...

<asp:Repeater id="dlEducation" onitemdatabound="dlEducation_ItemDataBound" runat=server>
0
 
Elvio Lujan.Net Senior DeveloperCommented:
make a break point in the error line... and evaluate the "dlEducation" valor... an tell me is it have an nothing value
0
 
TransBindAuthor 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

0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Elvio Lujan.Net Senior DeveloperCommented:
and how you are declaring the dlEducation repeater control?
0
 
TransBindAuthor 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>
0
 
TransBindAuthor 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 ...
0
 
Elvio Lujan.Net Senior DeveloperCommented:
can you try this?...

dlEducation = this.FindControl("dlEducation");
dlEducation.DataSource = DV;
0
 
TransBindAuthor 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;
0
 
TransBindAuthor Commented:
what an idiot i am ....
0
 
Elvio Lujan.Net Senior DeveloperCommented:
don't worry... i haven't see too :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.