• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

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?
0
TransBind
Asked:
TransBind
  • 5
  • 5
1 Solution
 
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
 
Elvio Lujan.Net Senior DeveloperCommented:
and how you are declaring the dlEducation repeater control?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
 
Elvio Lujan.Net Senior DeveloperCommented:
sure...

<asp:Repeater id="dlEducation" onitemdatabound="dlEducation_ItemDataBound" runat=server>
0
 
TransBindAuthor Commented:
what an idiot i am ....
0
 
Elvio Lujan.Net Senior DeveloperCommented:
don't worry... i haven't see too :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now