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

RadGrid not DataBound by PreRender

3 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Diane
Top achievements
Rank 1
Diane asked on 23 Mar 2009, 03:12 PM
Hi,

I am having difficulty with the RadGrid control (inside a user control) not databinding items by the PreRender event. The documentation says the lifecycle is as follows:

First page load:
Page.Load
Grid_Instance.NeedDataSource
Foreach Item in Grid_Instance:
   ItemCreated
   ItemDataBound
Page.PreRender

I am binding to a ObjectDataSource control:

  <telerik:RadGrid ID="rgProgrammes" runat="server" AutoGenerateColumns="False"
  DataSourceID="ods_Programmes" GridLines="None" Skin="Office2007">
                <MasterTableView DataKeyNames="pim_ID, CombinedCode" DataSourceID="ods_Programmes">

(i also bind to a GridView to check if that works)
Then in code behind I do a simple check for if it has databound :

    protected void Page_PreRender(object sender, EventArgs e)
    {
        int test = rgProgrammes.Items.Count; //result = 0
        int test2 = GridView1.Rows.Count; //result = 3
    }

Have I misunderstood something about the lifecycle of the RadGrid? When I insert breakpoints in my code, the Page_PreRender
event gets called before the RadGrid_DataBound event. This is giving me difficulty using a RadGrid in a user control
.

Any help would be appreciated.
Tom




3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 26 Mar 2009, 09:39 AM
Hello TomL,

Please, note that the case you are looking at in the documentation uses the NeedDataSource event to bind the grid - in this case the event sequence follows precisely the one given in the help article. However, when you set the DataSourceID property of the grid - the sequence of the events on initial page load is different - the Page_Prerender event comes before the grid's ItemDataBound.

Best Regards,
Tsvetoslav
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
adamhughes
Top achievements
Rank 1
Veteran
answered on 26 Apr 2019, 02:46 AM
So, when client data binding, how to make sure PreRender comes after data has been bound?
0
Eyup
Telerik team
answered on 30 Apr 2019, 07:53 AM
Hello,

The PreRender event is raised on server-side. When using client-side binding for the grid, there is no data at server-side at all. The grid gets its content on client-side and you can use JavaScript function with the client-side events provided by the grid to capture this moment. For example - OnRowDataBound:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/client-side-programming/events/onrowdatabound

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Diane
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
adamhughes
Top achievements
Rank 1
Veteran
Eyup
Telerik team
Share this question
or