locked
Problem while binding the ObjectDataSource RRS feed

  • Question

  • User-614943948 posted

    I am using this source code to bind the GridView using an objectDataSource

    <asp:GridView ID="grdReport" runat="server" EmptyDataText="No Login history record found."
                        DataSourceID="LoginHistoryDetails" AllowPaging="True"
                        AutoGenerateColumns="False" PageSize="7" CssClass="Table Table-striped Table-bordered Table-hover"
                        EnableTheming="False">
                        <Columns>
                            <asp:BoundField DataField="userid" HeaderText="User ID" />
                            <asp:BoundField DataField="LoginDate" HeaderText="Date" />
                            <asp:BoundField DataField="LoginTime" HeaderText="Time" />
                            <asp:BoundField DataField="Success" HeaderText="Success" />
                            <asp:BoundField DataField="Reason" HeaderText="Reason" />
                        </Columns>
                        <HeaderStyle Font-Size="12px" />
                    </asp:GridView>

    <asp:ObjectDataSource ID="LoginHistoryDetails" runat="server" TypeName="BAL.BALFactory.Instance.BL_CustomerMaster" 
                        SelectMethod="BindGridLoginHistory_V2" EnablePaging="true" MaximumRowsParameterName="pageSize" 
                        StartRowIndexParameterName="startRowIndex" SelectCountMethod="TotalRowCount" SortParameterName="sortExpression">
                        <SelectParameters>
                            <asp:Parameter Name="pageSize" Type="Int32" />
                            <asp:Parameter Name="startRowIndex" Type="Int32" />
                            <asp:Parameter Name="sortExpression" Type="Int32" />
                        </SelectParameters>
                    </asp:ObjectDataSource>

    This is the handler...

    [DataObjectMethod(DataObjectMethodType.Select, true)]
            public DataSet BindGridLoginHistory_V2(Int32 startRowIndex, Int32 pageSize, String sortExpression)
            {
                SqlCommand cmd = new SqlCommand();
                DataSet ds = new DataSet();
    
                cmd.CommandText = "usp_LoginHistory";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@PageSize", startRowIndex);
                cmd.Parameters.AddWithValue("@CurrentPage", pageSize);
                cmd.Parameters.AddWithValue("@SortExpression", sortExpression);
    
                ds = PrjClass.GetData(cmd);
                return ds;
            }
    [DataObjectMethod(DataObjectMethodType.Select, true)]
            public DataSet BindGridLoginHistory_V2(Int32 startRowIndex, Int32 pageSize, String sortExpression)
            {
                return DAL.DALFactory.Instance.DAL_Customer.BindGridLoginHistory_V2(startRowIndex, pageSize, sortExpression);
            }



    Why am I coming across this error at the run time?

    Wednesday, May 31, 2017 3:56:49 PM
    System.InvalidOperationException: The type specified in the TypeName property of ObjectDataSource 'LoginHistoryDetails' could not be found.
       at System.Web.UI.WebControls.ObjectDataSourceView.GetType(String typeName)
       at System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)
       at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
       at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
       at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
       at System.Web.UI.WebControls.GridView.DataBind()
       at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()
       at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()
       at System.Web.UI.Control.EnsureChildControls()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    Exception of type 'System.Web.HttpUnhandledException' was thrown.

    Wednesday, May 31, 2017 10:30 AM

All replies

  • User-1509636757 posted

    The error simply means that your class that holds the SelectMethod can not be found. Make sure your ObjectDataSource is pointing to a valid class via the TypeName property. If the class is in a different namespace, make sure to prefix your class with the proper namespace.

    Referenced link:

    1. The type specified in the TypeName property of ObjectDataSource 'ObjectDataSource1' could not be found. | The ASP.NET Forums
    2. The type specified in the TypeName property of ObjectDataSource 'ObjectDataSource1' could not be found. | The ASP.NET Forums

    To create an instance of the object that the ObjectDataSource control binds to, the control uses reflection to load the type that is identified by the type name at run time. Therefore, the value of the TypeName property can be a partially qualified type for code that is located in the Bin or App_Code directories or a fully qualified type name for code that is registered in the global assembly cache. If you use the global assembly cache, you must add the appropriate reference to the assemblies section of the Machine.config or Web.config file.

    further the type must have a default constructor. Have a look at the examples here http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.typename.aspx

    Wednesday, May 31, 2017 10:58 AM
  • User-614943948 posted

    Thank for giving your valuable time. 

    BAL.BALFactory.Instance.BL_CustomerMaster.BindGridLoginHistory_V2(0,0,"");

    In the CS file this class comes easily without any error, as you can see in the above mentioned code snippet, why is it happening this way with the ObjectDataSource?

    Wednesday, May 31, 2017 11:02 AM
  • User-1509636757 posted

    Make sure you are using fully qualified namespace along with classname (where BindGridLoginHistory_V2 method is defined) for ObjectDataSource.TypeName property.

    for example:

    namespace ABCProject.BAL.BalFactory.Instance
    {
        public class BL_CustomerMaster
        {
            public DataSet BindGridLoginHistory_V2()
    {
    }
    } }

    Then TypeName should be (watchout for case sensitivity): ABCProject.BAL.BalFactory.Instance.BL_CustomerMaster

    Wednesday, May 31, 2017 11:14 AM
  • User-271186128 posted

    Hi maverick786us,
    According to your error, you could check your code as the kaushlparik27 method. Also you can initialize TypeName property during Page_Init and not specifying TypeName directly in the ObjectDataSource. Code as below:

    public void Page_Init(object o, EventArgs e)
    {
       LoginHistoryDetails.TypeName = this.GetType().AssemblyQualifiedName;
    }
    

    .aspx(Delete the TypeName in the ObjectDataSource)

    <asp:ObjectDataSource ID="LoginHistoryDetails" runat="server" TypeName="BAL.BALFactory.Instance.BL_CustomerMaster" 
                        SelectMethod="BindGridLoginHistory_V2" EnablePaging="true" MaximumRowsParameterName="pageSize" 
                        StartRowIndexParameterName="startRowIndex" SelectCountMethod="TotalRowCount" SortParameterName="sortExpression">
                        <SelectParameters>
                            <asp:Parameter Name="pageSize" Type="Int32" />
                            <asp:Parameter Name="startRowIndex" Type="Int32" />
                            <asp:Parameter Name="sortExpression" Type="Int32" />
                        </SelectParameters>
                    </asp:ObjectDataSource>
    

    Best regards,
    Dillion

    Thursday, June 1, 2017 7:40 AM