This is a migrated thread and some comments may be shown as answers.

ObjectContainerDataSource + NeedDataSource posting multiple selects on RadGrid

3 Answers 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Katie
Top achievements
Rank 1
Katie asked on 24 Jan 2014, 10:20 PM
I am working with a RadGrid that, in the past, was simply bound to an ObjectContainerDataSource. Past, completely working grid:
<telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AllowAutomaticUpdates="True"
                            OnItemCommand="RadGrid_ItemCommand" OnItemDataBound="RadGrid_ItemDataBound" AllowPaging="true" PageSize="10"
                            OnPageSizeChanged="GridPageSizeChanged" 
                            AutoGenerateColumns="false" OnSortCommand="RadGrid_SortCommand" AllowMultiRowSelection="true"
                            OnItemCreated="RadGrid_ItemCreated" DataSourceID="RequestMasterDataSource" EnableViewState="true" >
                            <ExportSettings HideStructureColumns="true" />
                            <MasterTableView TableLayout="Fixed" RetrieveDataTypeFromFirstItem="true" CommandItemDisplay="Top">
                                <CommandItemSettings ShowExportToExcelButton="false" ShowAddNewRecordButton="false"
                                    ShowRefreshButton="false" />
                            </MasterTableView>
                            <ClientSettings>
                                <ClientEvents OnRowDblClick="SendSelectedRowToParent"></ClientEvents>
                                <Selecting AllowRowSelect="True"></Selecting>
                                <Scrolling AllowScroll="false"></Scrolling>
                                <ClientMessages DragToGroupOrReorder="Drag to group" />
                                <Resizing ResizeGridOnColumnResize="True" AllowRowResize="True" AllowColumnResize="True">
                                </Resizing>
                            </ClientSettings>
                            <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                            </HeaderContextMenu>
                        </telerik:RadGrid>

In the past few days, I've been fussing with this grid in order to change the data load from on page load to an ajax request. In the process of doing this, I needed to change the data binding method to the more advanced "NeedDataSource" binding. New grid:

<telerik:RadGrid ID="RadGrid" runat="server" GridLines="None" AllowAutomaticUpdates="True"
                            OnItemCommand="RadGrid_ItemCommand" OnItemDataBound="RadGrid_ItemDataBound" AllowPaging="true" PageSize="10"
                            OnPageSizeChanged="GridPageSizeChanged" 
                            AutoGenerateColumns="false" OnSortCommand="RadGrid_SortCommand" AllowMultiRowSelection="true"
                            OnItemCreated="RadGrid_ItemCreated" OnNeedDataSource="RadGrid_NeedDataSource" EnableViewState="true" >
                            <ExportSettings HideStructureColumns="true" />
                            <MasterTableView TableLayout="Fixed" RetrieveDataTypeFromFirstItem="true" CommandItemDisplay="Top">
                                <CommandItemSettings ShowExportToExcelButton="false" ShowAddNewRecordButton="false"
                                    ShowRefreshButton="false" />
                            </MasterTableView>
                            <ClientSettings>
                                <ClientEvents OnRowDblClick="SendSelectedRowToParent"></ClientEvents>
                                <Selecting AllowRowSelect="True"></Selecting>
                                <Scrolling AllowScroll="false"></Scrolling>
                                <ClientMessages DragToGroupOrReorder="Drag to group" />
                                <Resizing ResizeGridOnColumnResize="True" AllowRowResize="True" AllowColumnResize="True">
                                </Resizing>
                            </ClientSettings>
                            <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                            </HeaderContextMenu>
                        </telerik:RadGrid>
With the NeedDataSource method:

protected void RadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            if (configuration.DeferredLoad)
            {
                if (Page.IsPostBack)
                {
                    RadGrid.DataSource = RequestMasterDataSource;
                }
            }else
            {
                RadGrid.DataSource = RequestMasterDataSource;
            }
        }

Simple, and yet, suddenly my ObjectContainerDataSource (OCDS) is hitting the database 3 times instead of one. After some debugging, for some reason the OCDS is firing the selecting event 3 times (twice with the same selectingeventarguments and once with a different set). Please note, that no matter what the configuration.deferredload setting evaluates to (true or false), the selecting event is fired three times. Also note, the NeedDataSource method itself is not called three times, just the OCDS selecting method (though I cannot for the life of me pinpoint why).

So I'm wondering - is OCDS not supported with advanced data binding? Is there something else I'm missing (obvious or obscure)?

Any help of any kind greatly appreciated. Just a note, I've scrubbed all ID's and method names in the code blocks above to remove any identifying information. My grid is NOT named RadGrid, promise.

3 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 29 Jan 2014, 03:35 PM
Hi Katie,

You could not pass the id of the ObjectContainerDataSource as a DataSource of the grid through NeedDataSource event handler. Please check out the following live example and the following help article for additional information about using of advanced data-binding.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Katie
Top achievements
Rank 1
answered on 29 Jan 2014, 08:53 PM
Kostadin,

Can you please clarify - I have not passed the DataSourceId. I've passed the DataSource itself. Are you saying that any existing datasource cannot be used in the NeedDataSource event? That I need to create a DataTable full of data?

In other words, NeedDataSource does not work with ObjectContainerDataSource?
0
Kostadin
Telerik team
answered on 03 Feb 2014, 12:27 PM
Hello Katie,

You could not set the DataSource control as a DataSource of the RadGrid. Basically you have to get the collection of objects which is returned by the ObjectContainerDataSource and set it as a DataSource of the grid. You could bind RadGird the same way as you will bind to an asp:GridView programmatically but you do not need to call DataBind() method.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Katie
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Katie
Top achievements
Rank 1
Share this question
or