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

Set VirtualItemCount in server side

2 Answers 341 Views
Grid
This is a migrated thread and some comments may be shown as answers.
July
Top achievements
Rank 2
July asked on 21 Aug 2013, 03:51 PM
I need set VirtualItemCount after get the list of object.
Where I can set this?

I try in needSource and PageLoad event but does not work.

thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 22 Aug 2013, 10:37 AM
Hi,

I have tried to set the VirtualItemCount in the PageLoad and it works fine at my end.Here is the code snippet.

ASPX:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">   
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" ToolTip="" runat="server">
</telerik:RadAjaxLoadingPanel>
<telerik:RadGrid ID="RadGrid1" ShowGroupPanel="true" AllowFilteringByColumn="true" runat="server" AllowPaging="True" AllowSorting="true"    AllowCustomPaging="True" OnNeedDataSource="RadGrid1_NeedDataSource" OnGroupsChanging="RadGrid1_GroupsChanging"    OnColumnCreated="RadGrid1_ColumnCreated" >  
</telerik:RadGrid>

C#:
protected void Page_Load(object sender, EventArgs e)
   {
       RadGrid1.VirtualItemCount = 10000;//Set the VirtualItemCount
   }
     protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
       {
           MyBusinessObjects MyBusinessObjectCollection1 = new MyBusinessObjects();
           int startRowIndex = (ShouldApplySortFilterOrGroup()) ?
               0 : RadGrid1.CurrentPageIndex * RadGrid1.PageSize;
 
           int maximumRows = (ShouldApplySortFilterOrGroup()) ?
               MyBusinessObjectCollection1.SelectCount() : RadGrid1.PageSize;
 
           RadGrid1.AllowCustomPaging = !ShouldApplySortFilterOrGroup();
           RadGrid1.DataSource = MyBusinessObjectCollection1.Select(startRowIndex, maximumRows);
       }
 
       bool isGrouping = false;
       protected void RadGrid1_GroupsChanging(object source, GridGroupsChangingEventArgs e)
       {
           isGrouping = true;
           if (e.Action == GridGroupsChangingAction.Ungroup && RadGrid1.CurrentPageIndex > 0)
           {
               isGrouping = false;
           }
       }
 
       public bool ShouldApplySortFilterOrGroup()
       {
           return RadGrid1.MasterTableView.FilterExpression != "" ||
          RadGrid1.MasterTableView.GroupByExpressions.Count > 0 || isGrouping) ||
          RadGrid1.MasterTableView.SortExpressions.Count > 0;
       }
 
       protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
       {
           if(e.Column.IsBoundToFieldName("Date"))
           {
             (e.Column as GridDateTimeColumn).DataFormatString = "{0:D}";
           }
           else if (e.Column.IsBoundToFieldName("UnitPrice"))
           {
             (e.Column as GridNumericColumn).DataFormatString = "{0:C}";
           }
         if (e.Column is GridBoundColumn)
          {
            (e.Column as GridBoundColumn).FilterControlWidth = Unit.Pixel(100);
          }
       }    


Thanks,
Princy
0
July
Top achievements
Rank 2
answered on 22 Aug 2013, 11:53 AM
Hi Princy,
Finally I found other solutions, set ItermVirtualCount from ASPX using  ItemVirtualCount ="<%# GetCount() %>"

In server side 

public int GetCount(){
return "Number" ; 
}

Tags
Grid
Asked by
July
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
July
Top achievements
Rank 2
Share this question
or