Sharepoint 2010 - bind listview error message :Object reference not set to an instance of an object
-
09-12-2020 - |
Pregunta
I have an application page which retieve data from a stored procedure, my page give me the desired result but I discovrer in log table that this page have an error
System.NullReferenceException: Object reference not set to an instance of an object.
at PWC.SharePoint.Common.Layouts.PWC.RejectedReassessments.OnPreRender(EventArgs e)
when I debug I found this error in the line :
this.ReassessmentSelectorDataPager.DataBind();
this is the part of the code, I can't have further details
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
this.EnsureChildControls();
try
{
this.ApprovedReassessmentsListView.DataBind();
BindReassessmentSelectorToControl();
this.ReassessmentSelectorDataPager.DataBind();
}
catch (Exception ex)
{
LoggingUtilities.LogToDatabase(PWC_LOG_TYPE.ERROR, ex.Message, ex.ToString(), this.currentWeb.Url, this.currentWeb.CurrentUser.LoginName);
}
}
Help please ?
Solución
What I understand, When you debug you get Object reference not set to an instance of an object
at the data pager
control this.ReassessmentSelectorDataPager.DataBind();
This issue occurs if you tried at your code to set data pager ReassessmentSelectorDataPager
programmatically to null
like this DataPager ReassessmentSelectorDataPager = null;
so make sure that it's not set to null at any line in your code.
Also , no need to bind data pager control like this this.ReassessmentSelectorDataPager.DataBind();
it's related to a specific list view
that should be defined at PagedControlID
property at asp:DataPager
tag, so you need to set the data source of this listview then bind it like this
ListView1.DataSource = fucctionthat will retrive data to list view();
ListView1.DataBind();