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

RadGrid paging not with dynamically created radgrids

3 Answers 94 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Faizel
Top achievements
Rank 1
Faizel asked on 07 Aug 2012, 09:50 AM
Please assist:

Overview:
I retrieve data from a database. This data is grouped into sets and each set is displayed in its own RadGrid that I display dynamically. Because the amount of data groups that are returned are not always the same, the radgrids needs to be dynamically created and displayed.

Problem:
The Radgrids display correctly, however, paging does not work. When the page loads for the first time the all the radgrids displays correctly, with the correct amounts of rows, page numbers etc. However, when I click on any of the paging links it clears the page and does NOT fire the PageChanged or PageChanging event.


My Code:
                    Telerik.Web.UI.RadGrid grdDynamicIAData = new Telerik.Web.UI.RadGrid();
                    grdDynamicIAData.ID = "grv" + ia.Short_Name;
                    grdDynamicIAData.EnableViewState = true;
                    grdDynamicIAData.PageSize = 5;
                    grdDynamicIAData.AutoGenerateColumns = true;
                    grdDynamicIAData.AllowSorting = true;
                    grdDynamicIAData.AllowPaging = true;
                    grdDynamicIAData.PageIndexChanged += new GridPageChangedEventHandler(grdDynamicIAData_PageIndexChanged);

                    grdDynamicIAData.DataSource = dtDynamicIAData;
                    grdDynamicIAData.DataMember = dtDynamicIAData.TableName;
                    grdDynamicIAData.DataBind();


    void grdDynamicIAData_PageIndexChanged(object sender, Telerik.Web.UI.GridPageChangedEventArgs e)
    {
        Telerik.Web.UI.RadGrid grdDynamicIAData = (Telerik.Web.UI.RadGrid)sender;

        GeneratePopulateDataGrids("paging");
        grdDynamicIAData.CurrentPageIndex = e.NewPageIndex;
        grdDynamicIAData.DataBind();
    }


Thank you.



3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 07 Aug 2012, 12:00 PM
Hi Faizel,

Note that with simple data binding calling DataBind()method you need to change the pages manually as you will do with the standard MS GridView control in the same scenario.

If you would like these actions to be performed automatically, consider using advanced binding with NeedDataSource event handling.

Regards,
Pavlina
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
Faizel
Top achievements
Rank 1
answered on 08 Aug 2012, 09:22 AM
Pavlina,

Thank you for the information.

Your recommendation to use the advanced binding with NeedDataSource event handling worked in my case.

FYI, I WAS also doing the following

   protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            generate radgridview
        }
   }

this would cause the radgrids to only generate on the page load event or a page refresh and not when one clicked on any of the pager links. When I changed the code to

   protected void Page_Load(object sender, EventArgs e)
    {
            generate radgridview
     }

it worked.

Regards,
0
Pavlina
Telerik team
answered on 08 Aug 2012, 01:35 PM
Hi Faizel,

I recommend that you follow the instructions for creating RadGrid programmatically from the help article below:
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html

Greetings,
Pavlina
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.
Tags
Grid
Asked by
Faizel
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Faizel
Top achievements
Rank 1
Share this question
or