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

Change Page Size is not working

4 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Baal
Top achievements
Rank 1
Baal asked on 07 Oct 2011, 04:18 PM
I have a RadGrid whose skeleton is defined in the aspx page but the columns are defined at runtime.

<telerik:RadGrid ID="rgResult" runat="server" CellPadding="2" CellSpacing="2" AutoGenerateColumns="false" EnableViewState="false"
    AllowPaging="true" PageSize="25" AllowSorting="true" AllowMultiRowSelection="true"
    OnItemDataBound="rgResult_ItemDataBound" OnSortCommand="rgResult_SortCommand">
 
    <PagerStyle Mode="NextPrevNumericAndAdvanced" Position="Bottom"></PagerStyle>
 
    <ClientSettings EnableRowHoverStyle="true">
        <Selecting AllowRowSelect="true"></Selecting>
        <ClientEvents OnRowSelected="RowSelected" OnRowDeselected="RowDeselected" />
    </ClientSettings>
 
</telerik:RadGrid>


The columns are added when the user hits filter button, which shows only the columns that the user wants to see.

private void DesignRadGrid()
{
    rgResult.MasterTableView.Columns.Clear();
 
    var arrColumns = GetSelectedColumns();
    var arrPropertyInfo = typeof(MyObject).GetProperties(BindingFlags.Public | BindingFlags.Instance);
     
    var vColumns = from col in arrColumns.AsParallel().AsOrdered()
                    join pi in arrPropertyInfo.AsParallel() on col.Name equals pi.Name
                    select new
                            {
                                col.ColumnId,
                                col.DisplayName,
                                col.Name
                            };
     
    foreach (var oColumn in vColumns)
    {
        var boundColumn = new GridBoundColumn
                                {
                                    HeaderText = oColumn.DisplayName,
                                    DataField = oColumn.Name,
                                    SortExpression = oColumn.Name
                                };
         
        ... (format field according to datatype) ...
         
        rgResult.MasterTableView.Columns.Add(boundColumn);
    }
}


Now when I change the value in PageSize textbox in the pager section and click the button, the page size does not change. However, if I define the columns manually in the design page itself and not dynamically then it works fine.

So I added a OnPageSizeChanged event but it doesn't get fired. I haven't tried this with undynamic columns.

Thanks.

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 07 Oct 2011, 06:32 PM
Hello,

please use advance data binding for binding data.

There is not any such type of issue on radgrid.
please try to give sortexpression in column or EnableLinqExpression = "false" in grid.

Thanks,
Jayesh Goyani
0
Baal
Top achievements
Rank 1
answered on 11 Oct 2011, 09:47 PM
I am using ObjectDataSource, which I'm tying to the grid at runtime. There are multiple ObjectDataSource so I'll need to change the source depending on the condition.
0
Iana Tsolova
Telerik team
answered on 14 Oct 2011, 02:14 PM
Hello Baal,

If you want to change the column shown in RadGrid dynamically, I suggest that you try following the approach in this article.
Other then this, try running the page in debug mode and see if it breaks with some server-side errors.

Kind regards,
Iana Tsolova
the Telerik team
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 RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Baal
Top achievements
Rank 1
answered on 19 Oct 2011, 10:25 PM
Hmm, this might be my problem. I am not creating the grid during page_init. I am creating it during tab change event.

Let me try to force create during page_init and I'll let you know how it fares.

Thank you.
Tags
Grid
Asked by
Baal
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Baal
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or