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

[Solved] Paging problem

5 Answers 330 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Julio Lopes
Top achievements
Rank 1
Julio Lopes asked on 07 Jul 2009, 03:36 PM

Hello,

I have a problem with the paging of the RadGrid  that I have not been able to resolve . I define the grid in the page_load when the page is loaded for the first time as you can see in the next code:


private void DefineGridStructureGruposDisp() 
    { 
        RDG_GruposDisp.PagerStyle.ShowPagerText = true
        RDG_GruposDisp.AllowPaging = true
        RDG_GruposDisp.AllowCustomPaging = false
        //RDG_GruposDisp.VirtualItemCount = 100; 
        RDG_GruposDisp.AutoGenerateColumns = false
        RDG_GruposDisp.GridLines = GridLines.None; 
        RDG_GruposDisp.ClientSettings.Selecting.AllowRowSelect = false
 
        //Set options to enable Group-by 
        //RDG_GruposDisp.GroupingEnabled = true; 
        RDG_GruposDisp.ShowGroupPanel = false
        RDG_GruposDisp.ClientSettings.AllowDragToGroup = false
        RDG_GruposDisp.ClientSettings.AllowColumnsReorder = true
        //RDG_GruposDisp.MasterTableView.HierarchyLoadMode = GridChildLoadMode.ServerOnDemand; 
 
        RDG_GruposDisp.MasterTableView.NoDetailRecordsText = "No hay Grupos "
        RDG_GruposDisp.MasterTableView.NoMasterRecordsText = "No hay Grupos "
        RDG_GruposDisp.MasterTableView.EditMode = GridEditMode.EditForms; 
 
        RDG_GruposDisp.MasterTableView.AllowSorting = true
        RDG_GruposDisp.AllowMultiRowSelection = true
        //RDG_GruposDisp.ShowFooter = true; 
        RDG_GruposDisp.Width = Unit.Percentage(100); 
 
        // Configurar paginación 
        RDG_GruposDisp.MasterTableView.PageSize = 40; 
        RDG_GruposDisp.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric; 
 
        //Add columns 
 
        GridBoundColumn boundColumn = new GridBoundColumn(); 
        RDG_GruposDisp.MasterTableView.Columns.Add(boundColumn); 
        boundColumn.DataField = "idGrupos"
        boundColumn.HeaderText = "idGrupos"
        boundColumn.UniqueName = "idGrupos"
        //boundColumn.DataFormatString = "{0:##,##}"; 
        //boundColumn.Resizable = false; 
        boundColumn.ReadOnly = true
        boundColumn.ItemStyle.VerticalAlign = VerticalAlign.Middle; 
        boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center; 
        //boundColumn.FooterText = "Id Evento"; 
        boundColumn.Visible = false
 
        boundColumn = new GridBoundColumn(); 
        RDG_GruposDisp.MasterTableView.Columns.Add(boundColumn); 
        boundColumn.DataField = "Grupos"
        boundColumn.HeaderText = "Grupos"
        boundColumn.UniqueName = "Grupos"
        //boundColumn.DataFormatString = "{0:##,##}"; 
        //boundColumn.Resizable = false; 
        boundColumn.ReadOnly = true
        boundColumn.ItemStyle.VerticalAlign = VerticalAlign.Middle; 
        boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center; 
        //boundColumn.FooterText = "Grupo"; 
        boundColumn.Visible = true
    } 
 

I use needdatasource to pass data where i call the funtion through Rebind():

protected void RDG_GruposDisp_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    { 
        String Rebind = e.RebindReason.ToString(); 
 
        if (Rebind == "ExplicitRebind" || Rebind == "DetailTableBinding, PostBackEvent"
        {             
                RDG_GruposDisp.DataSource = eventos.GetGruposD_P(DDLProvincias.SelectedValue) ; 
        } 
    } 
 

The problem is that i can´t reset the paging of the grid, I mean if I first do a query where I select a value in the combobox that retrieves 1000 data after that I change that value in the combobox  now selecting 500 data and the paging is still  retrieving me  1000 data, the same number of pages when indeed it should just have 500 a half of pages . However in the grid are the data correctly but the client can be confused by thinking that there are more data that shows the paging. 

I hope that you understand what I wrote, sorry for my poor English.

 

Julio






private void DefineGridStructureGruposDisp() 
    { 
        RDG_GruposDisp.PagerStyle.ShowPagerText = true
        RDG_GruposDisp.AllowPaging = true
        RDG_GruposDisp.AllowCustomPaging = false
        //RDG_GruposDisp.VirtualItemCount = 100; 
        RDG_GruposDisp.AutoGenerateColumns = false
        RDG_GruposDisp.GridLines = GridLines.None; 
        RDG_GruposDisp.ClientSettings.Selecting.AllowRowSelect = false
 
        //Set options to enable Group-by 
        //RDG_GruposDisp.GroupingEnabled = true; 
        RDG_GruposDisp.ShowGroupPanel = false
        RDG_GruposDisp.ClientSettings.AllowDragToGroup = false
        RDG_GruposDisp.ClientSettings.AllowColumnsReorder = true
        //RDG_GruposDisp.MasterTableView.HierarchyLoadMode = GridChildLoadMode.ServerOnDemand; 
 
        RDG_GruposDisp.MasterTableView.NoDetailRecordsText = "No hay idGrupos "
        RDG_GruposDisp.MasterTableView.NoMasterRecordsText = "No hay idGrupos "
        RDG_GruposDisp.MasterTableView.EditMode = GridEditMode.EditForms; 
 
        RDG_GruposDisp.MasterTableView.AllowSorting = true
        //RDG_GruposDisp.MasterTableView.DataKeyNames = new string[] { "idEvento" }; 
        RDG_GruposDisp.AllowMultiRowSelection = true
        //RDG_GruposDisp.ShowFooter = true; 
        RDG_GruposDisp.Width = Unit.Percentage(100); 
 
        // Configurar paginación 
        RDG_GruposDisp.MasterTableView.PageSize = 40; 
        RDG_GruposDisp.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric; 
 
        //Add columns 
 
        GridBoundColumn boundColumn = new GridBoundColumn(); 
        RDG_GruposDisp.MasterTableView.Columns.Add(boundColumn); 
        boundColumn.DataField = "idGrupos"
        boundColumn.HeaderText = "idGrupos"
        boundColumn.UniqueName = "idGrupos"
        //boundColumn.DataFormatString = "{0:##,##}"; 
        //boundColumn.Resizable = false; 
        boundColumn.ReadOnly = true
        boundColumn.ItemStyle.VerticalAlign = VerticalAlign.Middle; 
        boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center; 
        //boundColumn.FooterText = "Id Evento"; 
        boundColumn.Visible = false
 
        boundColumn = new GridBoundColumn(); 
        RDG_GruposDisp.MasterTableView.Columns.Add(boundColumn); 
        boundColumn.DataField = "Grupos"
        boundColumn.HeaderText = "Grupos"
        boundColumn.UniqueName = "Grupos"
        //boundColumn.DataFormatString = "{0:##,##}"; 
        //boundColumn.Resizable = false; 
        boundColumn.ReadOnly = true
        boundColumn.ItemStyle.VerticalAlign = VerticalAlign.Middle; 
        boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center; 
        //boundColumn.FooterText = "Grupo"; 
        boundColumn.Visible = true
    } 
 




5 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 07 Jul 2009, 03:57 PM
Hi Julio,

Please have in mind that you should never call the Rebind() method in a NeedDataSource event handler.
For more information about creating RadGrid dynamically, please refer to the following help article:
Programmatic creation

Greetings,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Julio Lopes
Top achievements
Rank 1
answered on 07 Jul 2009, 04:25 PM
Hi,

I don't call Rebind() method in the NeedDataSource event handler, but i call the method from the Click event of a button:

protected void btnAceptar_Click(object sender, EventArgs e) 
    { 
                RDG_GruposDisp.Rebind(); 
    } 

Greetings, thanks for your reply

Julio
0
Julio Lopes
Top achievements
Rank 1
answered on 07 Jul 2009, 09:11 PM
Hola,

Para explicar el problema mejor en español ya que en inglés me cuesta mucho trabajo por si alguien entiende el idioma y me pudiera ayudar.

Utilizo un RadGrid donde en el page_load cuando se accede por primera vez a la página llamo a la función DefineGridStructureGruposDisp() donde configuro las columnas y sus propiedades. Tengo un RadCombobox donde puedo seleccionar una provincia o todas. Cuando le doy al botón Aceptar llamo a la función Rebind() del Grid para devolver los datos al datasource según la provincia seleccionada como se muestra arriba.

El problema está en que cuando escojo todas las provincias ella me devuelve por ejemplo 1000 items, donde el tamaño por  página es de 50 lo que habrian 20 páginas. Cuando quiero escoger otra provincia donde me devuelve menos de 1000 items, nunca me resetea la paginación, es decir, si devuelve 600 items deberían ser 12 páginas pero se mantiene con las 20 anteriores a pesar de haber menos elementos. He probado muchas maneras creando incluso el Grid de nuevo pero no he podido resolverlo.

Gracias y saludos,

Julio
0
Accepted
Pavlina
Telerik team
answered on 08 Jul 2009, 12:03 PM
Hi Julio,

I followed your scenario in order to replicate the issue but to no avail.
Attached to this message is a simple working project that  demonstrates the needed approach. Please give it a try and let me know what is the difference in your case.

Best wishes,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Julio Lopes
Top achievements
Rank 1
answered on 08 Jul 2009, 04:39 PM
Hola,

Gracias por la respuesta, ajusté a mi proyecto el código y me funcionó bien. Gracias de nuevo, saludos,

Julio
Tags
Grid
Asked by
Julio Lopes
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Julio Lopes
Top achievements
Rank 1
Share this question
or