none
Custom SPGridview Control

All replies

  • Please, try to add

    if (data == null)

        data = new DataView();

    to the begining of PerformingDataBinding method.


    Bond... Brooke Bond!

    Monday, March 26, 2012 7:37 AM
  • Hi All,

    I am adding a empty  datatable if the data(Datasource) is null...

    if(data==null)

    {

    base.PerformDataBinding(createDummyDataTable());

    return;

    }

      protected DataView  createDummyDataTable()
            {
             


                DataTable dt = new DataTable();
                foreach (SPBoundField dc in this.Columns)
                {
                  
                    dt.Columns.Add(dc.DataField.ToString());
                }

                DataRow dr = dt.NewRow();

                dt.Rows.Add(dr);

                return dt.DefaultView;

            }

    I am getting a new error now,when i click on the filter menu it throws an error "SPGridView_FilterCallbackErrorHandler() result = Object reference not set to an instance of an object"

    I get the above error only when i bind the empty datarow to the gridview.

    ameya


    • Edited by Amey0072 Monday, March 26, 2012 10:12 AM
    Monday, March 26, 2012 10:03 AM
  • Turn off filters when you are creating dummyDataTable:

    gridView1.AllowFiltering = false;

    And, of course turn them on when data-object contains data.


    Bond... Brooke Bond!


    • Edited by Aviw_ Monday, March 26, 2012 10:21 AM
    Monday, March 26, 2012 10:20 AM
  • Hi Aviw_PMPractice,

    Thanks for your quick reply.

    in which event do I set the filter property to false...?

    Ameya


    • Edited by Amey0072 Monday, March 26, 2012 10:39 AM
    Monday, March 26, 2012 10:26 AM
  • I know!

    But if you don't have data anyway, I think you can turn filters off painlessly.

    Or do you want to copy sharepoint list functionality exactly?


    Bond... Brooke Bond!

    Monday, March 26, 2012 10:40 AM

  • I need consistent grid views throughout the site...


    Ameya

    Monday, March 26, 2012 10:47 AM
  • What is your primary task?

    May be there is another way to accomplish it: BCS to .NET, SPListViewByQuery?

    Here someone said that there is only onу way to make filters like SharePoint's filters - create a new class inheriting from SPGridView and overriding GetCallbackResult.


    Bond... Brooke Bond!

    Monday, March 26, 2012 11:15 AM
  • I have lot of custom web parts using SPgridviews.I need them to behave and look similar to default SharePoint grids. The only issue I am having now if the error“Error"SPGridView_FilterCallbackErrorHandler() result =Object reference not set to an instance of an object" which I get when a datable containing empty data row is bound to the SPgridview(…done to show gridview
    headers when data source is empty) and the filter menu I clicked.


    Monday, March 26, 2012 11:33 AM
  • Try to handle empty data in ObjectDataSource, not in SPGridView!

    Add empty row to data at your select method!


    Bond... Brooke Bond!

    Monday, March 26, 2012 11:51 AM
  • I just tried to override the GetCallbackResult() method, but when I click the filter menu the function throws "Object reference not set to an instance of an object." error.

    Ameya




    Monday, March 26, 2012 12:47 PM
  • Hi All,

    I am handling the "NullReferenceException" in the GetCallbackResult method in my custom SPgridview control.The filter menu is now showing up but with a blank row at the bottom(...may be because i have added a blank row to the datasource to show gridview headers).

    Is there any way i can handle this by overriding the javascript functions in the SPGridview.js?

    Is there a better method to display gridview headers without adding a blank row in the datasource,but preserve the filter/sort menu on the headers?

    Regards,

    Ameya 

    Tuesday, March 27, 2012 9:11 AM
  • There is an "EmptyDataTemplate" in SPGridView. It shows when SPGridView don't contains the data.

    Don't happy, be worry...


    • Edited by Aviw_ Tuesday, March 27, 2012 9:57 AM
    Tuesday, March 27, 2012 9:57 AM
  • Hi Aviw_PMPractice,

    Using "EmptyDataTemplate" i can add colum structure but cannot preserve the default styles,filter ad sorting functionality.

    Anyone from MS,can you please help me on this.

    Ameya

    Thursday, March 29, 2012 7:28 AM