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

Error: DataSourceCount is not ready at this moment

2 Answers 184 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 19 Apr 2011, 10:58 PM
I'm getting this error: DataSourceCount is not ready at this moment
when my RadGrid initially has more than the PageSize number of records.  My PageSize="20" so I get that runtime error if the initial databind is with more than 20 rows.

Here is the declaration of the grid:

<oscarcontrols:OscarGrid runat="server" ID="grdProcessOrders" AutoGenerateColumns="false"
                            Visible="true" PageSize="20" AllowPaging="true" ShowHeader="true" Width="100%"
                            AllowSorting="true" EnableEmbeddedSkins="false" DataKeyNames="OrdID" OnPageIndexChanged="grdProcessOrders_PageIndexChanged"
                            OnPageSizeChanged="grdProcessOrders_PageSizeChanged" OnItemCommand="grdProcessOrders_ItemCommand"
                            OnSelectedIndexChanged="grdProcessOrders_SelectedIndexChanged" OnItemDataBound="grdProcessOrders_ItemDataBound"
                            OnDataBound="grdProcessOrders_DataBound" Skin="OSCARGridStyle1" OnSortCommand="grdProcessOrders_SortCommand"
                            OnItemCreated="grdProcessOrders_ItemCreated">
                            <ClientSettings EnableRowHoverStyle="true" EnableAlternatingItems="false" EnablePostBackOnRowClick="true">
                                <%--<ClientEvents OnGridCreated="ProcOrdGridCreate" /> --%>
                                <Selecting AllowRowSelect="True" />
                                <%-- <ClientEvents OnRowContextMenu="RowContextMenu" /> --%>
                            </ClientSettings>
                            <PagerStyle Position="TopAndBottom" Mode="NumericPages" Width="100%" AlwaysVisible="false" />
                            <MasterTableView OnPreRender="grdProcessOrders_PreRender" DataKeyNames="OrdID">
                                <NoRecordsTemplate>
                                    <oscarcontrols:OscarPanel runat="server" ID="pnlNoRecords" Width="100%" CssClass="procOrdersNoRecordsFound">
                                        <h2>
                                            <oscarcontrols:OscarLabel runat="server" ID="lblSorry" Text="Sorry. Try Again." /></h2>
                                        <oscarcontrols:OscarLabel runat="server" ID="lblNoRecords" Text="There were no records found that matched your search criteria." /><br />
                                        <br />
                                    </oscarcontrols:OscarPanel>
                                </NoRecordsTemplate>
                                <PagerTemplate>
                                    <table width="100%">
                                        <tr>
                                              
                                            <td style="padding-left: 5px">
                                            <oscarcontrols:OscarLabel runat="server" ID="lblResultsFoundValue" Text='<%# DataBinder.Eval(Container, "Paging.DataSourceCount")%>'
                                                    Font-Bold="true" /> 
                                                <b>
                                                    <oscarcontrols:OscarLabel runat="server" ID="lblResultsFound" Text="Results Found."
                                                        Font-Bold="true" /></b>
                                            </td>
                                            <td align="right" style="padding-right: 5px">
                                                <table>
                                                    <tr>
                                                        <td>
                                                            <oscarcontrols:OscarLabel runat="server" ID="lblResultPerPage" Text="Results per Page:" />
                                                            <oscarcontrols:OscarComboBox ID="ProcOrdRadComboBox1" DataSource="<%# new object[]{10, 20, 30, 40, 50} %>"
                                                                SelectedValue='<%# DataBinder.Eval(Container, "Paging.PageSize") %>' Style="margin-right: 20px;"
                                                                Width="40px" runat="server" OnClientSelectedIndexChanged="ProcOrdRadComboBox1_SelectedIndexChanged">
                                                            </oscarcontrols:OscarComboBox>
                                                        </td>
                                                        <td>
                                                            <oscarcontrols:OscarImageButton ID="Button1" runat="server" ImageUrl="~/Images/PagingFirst.gif"
                                                                OnClientClick="ProcOrdchangePage('first'); return false;" CommandName="Page"
                                                                CommandArgument="First" />
                                                            <oscarcontrols:OscarImageButton ID="Button2" runat="server" ImageUrl="~/Images/PagingPrev.gif"
                                                                OnClientClick="ProcOrdchangePage('prev'); return false;" CommandName="Page" CommandArgument="Prev" />
                                                        </td>
                                                        <td>
                                                            <oscarcontrols:OscarPanel runat="server" ID="NumericPagerPlaceHolder" />
                                                        </td>
                                                        <td>
                                                            <oscarcontrols:OscarImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/PagingNext.gif"
                                                                OnClientClick="ProcOrdchangePage('next'); return false;" CommandName="Page" CommandArgument="Next" />
                                                            <oscarcontrols:OscarImageButton ID="ImageButton2" runat="server" ImageUrl="~/Images/PagingLast.gif"
                                                                OnClientClick="ProcOrdchangePage('last'); return false;" CommandName="Page" CommandArgument="Last" />
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                    </table>
                                </PagerTemplate>

And here's the code that does the binding:
 

 

grdProcessOrders.DataSource = GetSortedOrders(false); 
grdProcessOrders.DataBind(); 

 

 

 


This code is called within the Page_Load event of my aspx page.


2 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 25 Apr 2011, 01:58 PM
Hi Mike,

I tried to replicate the problem using the code given bellow and here the page is working without any error.

<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<script type="text/javascript">
 
  function RadNumericTextBox1_ValueChanged(sender, args) {
    var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
    tableView.page(sender.get_value());
  }
 
</script>
<script runat="server" type="text/C#">
  protected void Page_Load(object sender, EventArgs e)
  {
    RadGrid1.DataSource = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
    RadGrid1.DataBind();
  }
</script>
<div>
  <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" PageSize="5">
    <MasterTableView>
      <PagerTemplate>
        <div style="margin: 0px; float: right;">
          Displaying page
          <%# (int)DataBinder.Eval(Container, "Paging.CurrentPageIndex") + 1 %>
          of
          <%# DataBinder.Eval(Container, "Paging.PageCount")%>
          , items
          <%# (int)DataBinder.Eval(Container, "Paging.FirstIndexInPage") + 1 %>
          to
          <%# (int)DataBinder.Eval(Container, "Paging.LastIndexInPage") + 1 %>
          of
          <%# DataBinder.Eval(Container, "Paging.DataSourceCount")%>
        </div>
        <span style="vertical-align: middle;">Page:</span>
        <telerik:RadNumericTextBox ID="RadNumericTextBox1" Value='<%# (int)DataBinder.Eval(Container, "Paging.CurrentPageIndex") + 1 %>'
          runat="server">
          <ClientEvents OnValueChanged="RadNumericTextBox1_ValueChanged" />
          <NumberFormat DecimalDigits="0" />
        </telerik:RadNumericTextBox>
        DataSourceCount is:
        <asp:Label runat="server" ID="Label1" Text='<%# DataBinder.Eval(Container, "Paging.DataSourceCount")%>' />
        </div>
      </PagerTemplate>
    </MasterTableView>
  </telerik:RadGrid>
</div>
</form>

Did you make any modifications of the OscarGrid after inherit the RadGrid?

Regards,
Vasil
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Mike
Top achievements
Rank 1
answered on 25 Apr 2011, 02:59 PM
Hi Vasil,

Thank you for the help.

No, our oscargrid is simply the RadGrid - there have been no modifications made at this point.

One solution we found to resolve the error is to set the PageSize DDL's SelectedValue using the code behind rather than using the declarative DataBinder approach we originally used.

But...instead, we ended up removing the entire <PagerTemplate> section and now we're using the built-in <PagerStyle Mode=""> to control the pagination functionality.  To do this, we just had to do some more work on our custom Skin to get the first, prev, next, last images and other pagination elements to look right.

-Mike


Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Mike
Top achievements
Rank 1
Share this question
or