Resizing RadGrid in RadSplitter

This example shows how you can resize RadGrid when resizing its splitter container. The RadSplitter control exposes OnClientPaneResized client event which can be handled to initiate an AJAX request and then all you need to do is calculate and set the new value of the PageSize property on the server.

Additionally, to make the grid stretch inside the corresponding pane on horizontal resize, simply set the Width property of RadGrid to 100%.

Resize grid in splitter

Below is the code logic used in the example:

function ClientResized(sender, eventArgs) {
  $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest('ChangePageSize');
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
    <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
    <telerik:AjaxSetting AjaxControlID="RadGrid1">
        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
<telerik:RadSplitter RenderMode="Lightweight" ID="RadSplitter1" Width="700px" runat="server" Orientation="Horizontal">
  <telerik:RadPane ID="gridPane" runat="server" Height="200px" OnClientResized="ClientResized"
    <telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" AllowPaging="true" Width="700px" Skin="Telerik">
      <MasterTableView AllowPaging="true" />
      <PagerStyle Mode="NumericPages" />
  <telerik:RadSplitBar ID="RadSplitBar2" runat="server" EnableResize="True">
  <telerik:RadPane ID="listBoxPane" runat="server" CssClass="TextStyle">
    RadSplitter Prometheus enables you to build desktop-like application interfaces
    with resizable areas and sliding, dockable panels just like in Visual Studio .Net.
    Each layout can be indefinitely nested with splitters, whose state is automatically
    persisted on the server and can be saved/loaded through the extensive API.
private void Page_Load(object sender, System.EventArgs e)
    if (!Page.IsPostBack)
        //Set initial value of the PageSize property.                
        RadGrid1.PageSize = 6;
protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
    switch (e.Argument.ToString())
        case "ChangePageSize":
            * Calculate the number of rows that fit in the RadPane.                 
            * In this case 23 is the sum of the height of a single row and its upper border width.   
            * Depending on the paticular scenario this value may vary.       
            int rows = (Int32.Parse(this.gridPane.Height.Value.ToString()) - 60) / 23;
            if (rows >= 1)
                RadGrid1.PageSize = rows;
                // Check whether the CurrentPageIndex is correct.                    
                if (Session["itemsCount"] != null)
                    int itemsCount = (int)Session["itemsCount"];
                    int pageCount = (int)Math.Ceiling(((double)itemsCount / rows));
                    if (RadGrid1.MasterTableView.CurrentPageIndex > pageCount - 1)
                        RadGrid1.MasterTableView.CurrentPageIndex = pageCount - 1;
private void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    String ConnString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
    SqlConnection conn = new SqlConnection(ConnString);
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = new SqlCommand("SELECT CustomerID, CompanyName, ContactName, ContactTitle FROM Customers", conn);
    DataTable myDataTable = new DataTable();
    Session["itemsCount"] = myDataTable.DefaultView.Count;
    RadGrid1.DataSource = myDataTable;

Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If Not Page.IsPostBack Then
        RadGrid1.PageSize = 6
    End If
End Sub
Private Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
    Dim ConnString As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString
    Dim conn As SqlConnection = New SqlConnection(ConnString)
    Dim adapter As SqlDataAdapter = New SqlDataAdapter
    adapter.SelectCommand = New SqlCommand("SELECT CustomerID, CompanyName, ContactName, ContactTitle FROM Customers", conn)
    Dim table1 As New DataTable
    End Try
    RadGrid1.DataSource = table1
End Sub
Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
End Sub
Private Sub InitializeComponent()
End Sub
Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As UI.AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest
    Select Case e.Argument.ToString()
        Case "ChangePageSize"
            Dim rows As Integer = (Int32.Parse(Me.gridPane.Height.Value.ToString()) - 60) / 23
            If rows >= 1 Then
                RadGrid1.PageSize = rows
            End If
            Exit Select
    End Select
End Sub
In this article
Not finding the help you need? Improve this article