CodeSmith Community
Your Code. Your Way. Faster!

GridViewSearchPanel problem when datasource based on a View

Latest post 07-11-2007 9:09 AM by mike123. 8 replies.
  • 03-23-2007 11:16 AM

    • david849
    • Top 500 Contributor
    • Joined on 03-13-2007
    • Posts 12
    • Points 275

    GridViewSearchPanel problem when datasource based on a View

    I get the error below when I try using a GridViewSearchPanel with a data source that is based on a View.  I also have a data source that is based on a table that is identical to view with the exception the view has one extra nvarchar(string) column.  The crazy thing is that the search panel works great on the table based data source.  But when I switch the datasource tag name...it blows up!

     Does anyone have any ideas?

     

    Server Error in '/Website.AJAX' 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 296:                    ColumnEnumAttribute cea = EntityHelper.GetAttribute<ColumnEnumAttribute>( (Enum)c.GetValue( i ) );
    Line 297: // only show fields that we can realistically search against
    Line 298: switch ( cea.DbType )
    Line 299: {
    Line 300: case System.Data.DbType.AnsiString:

    Source File: C:\Web\UI\GridViewSearchPanel.cs    Line: 298

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
    Web.UI.GridViewSearchPanel.CreateChildControls() in C:\Web\UI\GridViewSearchPanel.cs:298
    System.Web.UI.Control.EnsureChildControls() +87
    Web.UI.GridViewSearchPanel.set_SearchFieldName(String value) in C:\Web\UI\GridViewSearchPanel.cs:149
    Web.UI.GridViewSearchPanelState.RestoreState(GridView& gridView, GridViewSearchPanel& searchPanel) in C:\Web\UI\GridViewSearchPanelState.cs:151
    Web.UI.<>c__DisplayClass39.<HandleGridViewSearchPanelState>b__2f(Object sender, EventArgs e) in C:\Web\UI\FormUtilBase.generated.cs:1458
    System.EventHandler.Invoke(Object sender, EventArgs e) +0
    System.Web.UI.Control.OnLoad(EventArgs e) +99
    System.Web.UI.Control.LoadRecursive() +47
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

     Here's my code:

                         <dataAms:GridViewSearchPanel ID="GridViewSearchPanel2" runat="server" GridViewControlID="GridView1" Visible="true" />
            <br />
            <dataAms:EntityGridView ID="GridView1" runat="server"           
                    AutoGenerateColumns="False"                   
                    DataSourceID="SiteDrugDataSource"
                    DataKeyNames="SiteDrugId"
                    AllowMultiColumnSorting="false"
                    DefaultSortColumnName=""
                    DefaultSortDirection="Ascending"   
                    ExcelExportFileName="Export_SiteDrug.xls"         
                >
                <Columns>
                    <asp:CommandField ShowSelectButton="True" ShowEditButton="True" />               
                    <asp:BoundField DataField="Strength" HeaderText="Strength" SortExpression="Strength"  />
                    <asp:BoundField DataField="Units" HeaderText="Units" SortExpression="Units"  /> SortExpression="NameOfCodingSystem"  />
                    <asp:BoundField DataField="InsertedDateTime" HeaderText="Inserted Date Time" SortExpression="InsertedDateTime"  />
                    <asp:BoundField DataField="ModifiedDateTime" HeaderText="Modified Date Time" SortExpression="ModifiedDateTime"  />
                </Columns>
                <EmptyDataTemplate>
                    <b>No SiteDrug Found!</b>
                </EmptyDataTemplate>
            </dataAms:EntityGridView>
            <br />
            <asp:Button runat="server" ID="btnSiteDrug" OnClientClick="BLOCKED SCRIPTlocation.href='/admin/SiteDrugEdit.aspx'; return false;" Text="Add New"></asp:Button>
               
            <dataAms:SiteDrugsViewWithGroupDrugNameDataSource ID="SiteDrugDataSource" runat="server"
                SelectMethod="GetPaged"
                EnablePaging="True"
                EnableSorting="True"
            >
                <Parameters>
                    <dataAms:CustomParameter Name="WhereClause" Value="" ConvertEmptyStringToNull="false" />
                    <dataAms:CustomParameter Name="OrderByClause" Value="" ConvertEmptyStringToNull="false" />
                    <asp:ControlParameter Name="PageIndex" ControlID="GridView1" PropertyName="PageIndex" Type="Int32" />
                    <asp:ControlParameter Name="PageSize" ControlID="GridView1" PropertyName="PageSize" Type="Int32" />
                    <dataAms:CustomParameter Name="RecordCount" Value="0" Type="Int32" />
                </Parameters>
            </dataAms:SiteDrugDataSource>
     

     

    Filed under:
    • Post Points: 35
  • 03-23-2007 1:25 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,910

    Re: GridViewSearchPanel problem when datasource based on a View

    Fixed (rev. 526)

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 35
  • 03-26-2007 9:10 AM In reply to

    • david849
    • Top 500 Contributor
    • Joined on 03-13-2007
    • Posts 12
    • Points 275

    Re: GridViewSearchPanel problem when datasource based on a View

    I downloaded the latest nightly build ( 20070326 ) and just regenerated my files.   I'm still getting an error on line 298, but the stack trace output is now different...

     Any help is greatly appreciated!!!

    Source Error:

    Line 296:                    ColumnEnumAttribute cea = EntityHelper.GetAttribute<ColumnEnumAttribute>( (Enum)c.GetValue( i ) );
    Line 297:                    // only show fields that we can realistically search against
    Line 298:                    switch ( cea.DbType )
    Line 299:                    {
    Line 300:                        case System.Data.DbType.AnsiString:
     

    Source File: C:\Data\Projects\A\ATools\M.A.Site.Web\UI\GridViewSearchPanel.cs    Line: 298

    Stack Trace:


    [NullReferenceException: Object reference not set to an instance of an object.]
       M.A.Site.Web.UI.GridViewSearchPanel.CreateChildControls() in C:\Data\Projects\A\ATools\M.A.Site.Web\UI\GridViewSearchPanel.cs:298
       System.Web.UI.Control.EnsureChildControls() +87
       M.A.Site.Web.UI.GridViewSearchPanel.OnLoad(EventArgs e) in C:\Data\Projects\A\ATools\M.A.Site.Web\UI\GridViewSearchPanel.cs:242
       System.Web.UI.Control.LoadRecursive() +47
       System.Web.UI.Control.LoadRecursive() +131
       System.Web.UI.Control.LoadRecursive() +131
       System.Web.UI.Control.LoadRecursive() +131
       System.Web.UI.Control.LoadRecursive() +131
       System.Web.UI.Control.LoadRecursive() +131
       System.Web.UI.Control.LoadRecursive() +131
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

     Thanks,

    David 

    Filed under:
    • Post Points: 35
  • 03-26-2007 9:38 AM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,910

    Re: GridViewSearchPanel problem when datasource based on a View

    Reply |Contact |Answer

    David,

    GridViewSearchPanel is using reflection to get entity column attribute information, so the fix was to add ColumnEnum attribute when enumerating columns. Could you verify that in your EntityBase.generated.cs class where columns enum is defined, the ColumnEnum attribute is specified?

        /// <summary>
        /// Enumerate the CustomerandSuppliersbyCity columns.
        /// </summary>
        [Serializable]
        public enum CustomerandSuppliersbyCityColumn
        {
            /// <summary>
            /// City :
            /// </summary>
            [EnumTextValue("City")]
            [ColumnEnum("City", typeof(System.String), System.Data.DbType.String, false, false, true, 15)]
            City,
            /// <summary>
            /// CompanyName :
            /// </summary>
            [EnumTextValue("CompanyName")]
            [ColumnEnum("CompanyName", typeof(System.String), System.Data.DbType.String, false, false, false, 40)]
            CompanyName,
            /// <summary>
            /// ContactName :
            /// </summary>
            [EnumTextValue("ContactName")]
            [ColumnEnum("ContactName", typeof(System.String), System.Data.DbType.String, false, false, true, 30)]
            ContactName,
            /// <summary>
            /// Relationship :
            /// </summary>
            [EnumTextValue("Relationship")]
            [ColumnEnum("Relationship", typeof(System.String), System.Data.DbType.AnsiString, false, false, false, 9)]
            Relationship
        }//End enum

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 35
  • 03-26-2007 12:50 PM In reply to

    • basolutions
    • Top 100 Contributor
    • Joined on 03-21-2007
    • Denver, CO
    • Posts 51
    • Points 1,175

    Re: GridViewSearchPanel problem when datasource based on a View

    I was having the same issue with view generated entities, but I downloaded the latest build and it looks like it fixed it.  Thanks for the patch!

     One quick question on the GridViewSearchPanel:

    Is it possible to not have it show hidden columns in the dropdown list of columns?  I don't exactly want external users searching with an internally generated id key, but I need it in the view so that I can pass the next page the correct key.

     Any ideas?

    Thanks again!

    Jesse

    • Post Points: 35
  • 03-26-2007 1:00 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,910

    Re: GridViewSearchPanel problem when datasource based on a View

    Jesse,

    Here is how to exclude fields from the column list:

    <data:GridViewSearchPanel ID="GridViewSearchPanel1" runat="server" GridViewControlID="GridView1" Visible="true">
        <FieldsToExclude>
            <data:Field Value="City" />
            <data:Field Value="Country" />
        </FieldsToExclude>

    </data:GridViewSearchPanel>

     

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 65
  • 03-26-2007 1:11 PM In reply to

    • david849
    • Top 500 Contributor
    • Joined on 03-13-2007
    • Posts 12
    • Points 275

    Re: GridViewSearchPanel problem when datasource based on a View

    It's working great for me now as well!
    Thanks,

    David 

    Filed under:
    • Post Points: 5
  • 07-11-2007 2:24 AM In reply to

    Thanks alot

    Thanks alot mike,

       Your solution for excluding fields from column list of GridViewSearchPanel helped me alot.

      Can u provide me the functionality of "GetPaged" ,"Get","GetAll","GetByCodeId","Find" properties of "SelectMethod" in "EntityDataSource" control.

    regards,

    Rajeev.P

    Regards, Rajeev P
    • Post Points: 35
  • 07-11-2007 9:09 AM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,910

    Re: Thanks alot

    Rajeev,

    Please elaborate more on what you're trying to achieve.

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 5
Page 1 of 1 (9 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems