Hi,
I am following the tutotial from 4GuysFromRolla to implement custom paging for my web page.
Currently, I have the following set up:
GetTransactionCount - Stored procedure that returns the total number of results, used to determine how many pages will be needed GetPageTransactions - Stored procedure that returns the specific page of results to be displayed
These two are accessed through two methods in a DataSet which is in turn accessed through a fairly simple class with just two methods in it:
//return how many rows are in the total recordset
public int GetTransactionCount(int fkToOrgID)
{
return (int)Adapter.usp_GetTransactionCount(fkToOrgID);
}
//get a page of transactions [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]public TW_Transaction.TW_TransactionXXXDataTable GetPageTransactions(int maximumRows, int startRowIndex, string sortExpression, int fkToOrgID)
{
return Adapter.GetPageTransactions(startRowIndex, maximumRows, sortExpression, fkToOrgID);
}
fkToOrgID is an integer used to select records based on a company ID field (pretty basic stuff
). There is no C# code at the moment as I am just familiarising myself with ASP.net and trying to keep it simple (maybe that is my problem!). I have a drop down list (ddlTradPartyTo) which is the source of this parameter. If I run the query with no parameters (so return results for all copanies) it works 100% fine - paging, sorting no problem. Only when I introduce parameters does this problem occur! The code compiles fine, but when launched produces the error below.
The ASP code for my ObjectDataSource:
<asp:ObjectDataSource ID="ODS" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetPageTransactions" TypeName="BLL"EnablePaging="True" SelectCountMethod="GetTransactionCount" SortParameterName="sortExpression">
<SelectParameters>
<asp:ControlParameter ControlID="ddlTradPartyTo" Name="fkToOrgID" PropertyName="SelectedValue" Type="string" DefaultValue="0" />
</SelectParameters>
</asp:ObjectDataSource>
The ASP code for my GridView:
<%--Gridview--%>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataSourceID="ODS" ForeColor="#333333" GridLines="None" DataKeyNames="pkTransactionID">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="pkTransactionID" HeaderText="pkTransactionID" InsertVisible="False"
ReadOnly="True" SortExpression="pkTransactionID" />
<asp:BoundField DataField="fkDocClassCD" HeaderText="fkDocClassCD" SortExpression="fkDocClassCD" />
<asp:BoundField DataField="fkFromOrgID" HeaderText="fkFromOrgID" SortExpression="fkFromOrgID" />
<asp:BoundField DataField="fkToOrgID" HeaderText="fkToOrgID" SortExpression="fkToOrgID" />
<asp:BoundField DataField="fkErrorCode" HeaderText="fkErrorCode" SortExpression="fkErrorCode" />
<asp:BoundField DataField="fkStatus" HeaderText="fkStatus" SortExpression="fkStatus" />
<asp:BoundField DataField="DateTimeReceived" HeaderText="DateTimeReceived" SortExpression="DateTimeReceived" />
<asp:BoundField DataField="DateTimeSent" HeaderText="DateTimeSent" SortExpression="DateTimeSent" />
<asp:BoundField DataField="NetFileSize" HeaderText="NetFileSize" SortExpression="NetFileSize" />
</Columns>
</asp:GridView>
The ASP code for my DataSource (for the GridView):
<asp:SqlDataSource ID="sqlOrganisations" runat="server" ConnectionString="<%$ ConnectionStrings:RobConnectionString %>"
SelectCommand="SELECT [pkOrganisationID], [OrganisationName] FROM [CO_Organisation] ORDER BY [OrganisationName]">
</asp:SqlDataSource>
The error that is generated is :
Server Error in '/GridViewPrac' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 29: public int GetTransactionCount(int fkToOrgID)
Line 30: {
Line 31: return (int)Adapter.usp_GetTransactionCount(fkToOrgID);
Line 32: }
Line 33: |
Source File: c:\Dev\Training\GridViewPrac\App_Code\BLL\BLL.cs Line: 31
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
BLL.GetTransactionCount(Int32 fkToOrgID) in c:\Dev\Training\GridViewPrac\App_Code\BLL\BLL.cs:31
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +72
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +358
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +482
System.Web.UI.WebControls.ObjectDataSourceView.QueryTotalRowCount(IOrderedDictionary mergedParameters, DataSourceSelectArguments arguments, Boolean disposeInstance, Object& instance) +254
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +2186
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +41
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360 |
The error seems to be to do with my BLL and using the DLL as the source for the value. But if this is the case how can i work around or it or what am I doing wrong?
Any help greatly appreciated, please say if any more info is needed.