Current filter:
                                You should refresh the page.
                                Support Center
                                  • I am binding the ASPxGridView to the DataSource at runtime using the following code:

                                    protected void Page_Load(object sender, EventArgs e) { ... if (!IsPostBack) { ASPxGridView1.DataSource = SomeDataTable; ASPxGridView1.DataBind(); } }

                                    In this case, sorting, paging, filtering ... does not work in the ASPxGridView. Why it is so?

                                1 Solution

                                Creation Date Rating Importance Sort by

                                Indeed, in this case, the ASPxGridView won't be able to work properly. This is because the ASPxGridView does not cache data, so you must provide it to the control at the every request to the server. Here is the code which must be used when setting the control's DataSource at runtime:

                                protected void Page_Init(object sender, EventArgs e) { // initialize SomeDataTable ASPxGridView1.DataSource = SomeDataTable; ASPxGridView1.DataBind(); } protected void Page_Load(object sender, EventArgs e) { ... }

                                With the newest version ASPxGridView supports the caching mechanism (it is enabled by default). If you wish to use it and bind the grid at runtime, use the approach posted in the ‘Bind a grid to a DataTable via code’ example. In this case, ASPxGridView will be re-populated only when it requires data. In other cases the grid will take data from its own custom callback state. You can learn more about this mechanism here:

                                ASPxGridView Row Cache

                                Here is some code snippet:

                                protected void Page_Load(object sender, EventArgs e) { //Bind the grid only once if (!IsPostBack) grid.DataBind(); } protected void grid_DataBinding(object sender, EventArgs e) { // Assign the data source in grid_DataBinding grid.DataSource = GetTable(); }

                                See Also:
                                How to bind ASPxGridView to data when clicking an external button
                                How to bind ASPxGridView to data when applying filtering via Filter Row
                                Bind a grid to a DataTable via code

                                An additional potential cause of this misbehavior is non-unique key values. In other words, values of the field specified via the ASPxGridView.KeyFieldName property must be unique.


                                You may ask why the ASPxGridView does not cache data automatically as it is implemented in the standard asp:GridView control. To give you an answer to this question we need to discuss the ViewState concept. The ViewState in ASP.NET is used to store the current state of a control. For example, review the Understanding ASP.NET View State webpage to learn more on this subject. Note, however, that there is a significant difference between the standard asp:GridView control and our ASPxGridView control. The asp:GridView control stores all data rows in the ViewState; for this reason, the overall page ViewState size might be very large. The only benefit of this behavior is that you can bind the asp:GridView control to data on the initial page load without the need to bind it on subsequent page requests (e.g., see Dynamically create DataTable and bind to GridView in ASP.Net). In our ASPxGridView, the datasource is not stored in the ViewState for performance reasons, and you need to supply a valid datasource on every page request. Other settings and the callback state are stored in the ViewState if the EnableViewState option is enabled. It makes sense to disable this option only if you create the ASPxGridView control dynamically and you initialize all necessary settings manually (e.g., see E321 - How to create the ASPxGridView at runtime). In this scenario, you do not need to keep settings between postbacks because you recreate the controls hierarchy on every round trip to the server (see also: KA18606 - How to create controls dynamically).

                                Show all comments
                                • Harika Gandham 05.28.2012

                                  protected dataset binddata()
                                    your sourcecode here and
                                  bind grid
                                  then return dataset
                                  protected void page_load()

                                • Madhan Ponnusamy 06.26.2012

                                  What difference it will make, if the code inside page_init is in page_load without IsPostback check

                                • If ASPxGridView does not have a data source when it is required, the control behavior is unexpected. For example, if the Row Cache is disabled, ASPxGridView requests data before the Load event is raised. If you assign a data source at runtime in the page Load event handler, this can cause an issue.

                                • sparco 06.29.2012

                                  I think loading the data every postback is expensive. Just load the data during the PageIndexChanged or BeforeColumnSortingGrouping, or ProcessColumnAutoFilter.

                                • I am not sure that this solution is universal. However, if it operates as expected in your scenario, I believe that it can be used as well.

                                • Veeramani Dhanakodi 1 01.26.2015

                                  Hi Plato,
                                  Thank you so much. It working fine with out any issues.

                                • Daniel Mate 07.07.2015

                                  Ah, this works great. The only Issue I noticed though is that loading grid pages now takes longer. Is that normal behavior or am I missing something?

                                • Anthony (DevExpress Support) 07.07.2015


                                  To process your recent post more efficiently, I created a separate ticket on your behalf: T264274: ASPxGridView - It takes some time to load grid pages. This ticket is currently in our processing queue. Our team will address it soon.

                                • Yan Xiaohua 09.29.2015

                                  What shall we do if the source table structure may change ?  e.g: click button1 return product list, but click button2, return customer list?

                                • I see that you asked this question in the T294715: ASPxGridView can not sorting ticket. Let's continue our conversation in that ticket.
                                • goo gaa 11.20.2015

                                  Hello devexpress. I need your help.  my ASPxTreelist's OnCustomCallback="trlGroup_CustomCallback". But gridview show nothing to display.
                                  protected void trlGroup_CustomCallback(object sender, TreeListCustomCallbackEventArgs e)
                                         ASPxTreeList treeList = sender as ASPxTreeList;
                                         //int parentid = 0;
                                         //ASPxTreeList treeList = (ASPxTreeList)sender;
                                         SqlCommand objCmd = new SqlCommand();
                                         objCmd.Connection = DBRes.objConn_Dotood;
                                         //TreeListNode treeNode = treeList.FindNodeByKeyValue(key);
                                             key = e.Argument.ToString();
                                             objCmd.CommandText = "SELECT tree.ID, tree.tName, training.ID, training.Name, road.ID, road.fileName, road.fileRoad FROM t_trainTree AS tree RIGHT JOIN t_training AS training ON tree.ID=training.treeID RIGHT JOIN t_fileroad AS road ON training.ID=road.t_ID WHERE tree.ID="+key;
                                             //DataTable dt = new DataTable();
                                             //SqlDataAdapter da = new SqlDataAdapter(objCmd);
                                             SqlDataReader dr = objCmd.ExecuteReader();
                                             grid_fileDesc.DataSource = dr;
                                         catch (Exception ex)
                                             objCmd.CommandText = "";
                                             MessageBox.Show("алдаа гарлаа" + ex);

                                • Hello,

                                  To process your recent post more efficiently, I created a separate ticket on your behalf: gridview show nothing to display. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

                                • smoore4 03.25.2016

                                  I don't love the idea of storing a table in a session (ie, GetTable()) or ViewState because I could have 100s of thousands of rows.  The initial response is what fixed it for me.  First, I store the select command in a session.  

                                  Session["sql_export"] = DataExportDS.SelectCommand;

                                  And then this seemed to take care of all my issues with paging....

                                  protected void Page_Init(object sender, EventArgs e) { if (Session["sql_export"] != null) { DataExportDS.SelectCommand = Session["sql_export"].ToString(); DataGrid.DataBind(); } }

                                • Barry Kaufman 1 07.20.2016
                                  I've tried using both of Plato's examples above but my grid won't show any data after changing the page.

                                  Here is where my code is at right now:
                                  Page Load: if (!IsPostBack) { ASPxGridViewReceipts.DataBind(); } protected void ASPxGridViewReceipts_DataBinding(object sender, EventArgs e) { ASPxGridViewReceipts.DataSource = sdsReceipts; //sdsReceipts = SQLDataSource }

                                  <dx:ASPxGridView ID="ASPxGridViewReceipts" runat="server" AutoGenerateColumns="False" KeyFieldName="DeliveryReceiptID" ClientInstanceName="ASPxGridViewReceipts" OnCustomCallback="ASPxGridViewReceipts_CustomCallback" Width="400px" OnDataBound="ASPxGridViewReceipts_DataBound" OnPreRender="ASPxGridViewReceipts_PreRender" OnDataBinding="ASPxGridViewReceipts_DataBinding"> <ClientSideEvents FocusedRowChanged="function(s, e) { document.getElementById(&quot;drCallbackMethod&quot;).value = &quot;fill&quot; DRCallback.PerformCallback(); }" /> <SettingsPager EnableAdaptivity="True" NumericButtonCount="5"> </SettingsPager> <SettingsBehavior AllowSelectByRowClick="True" AllowSelectSingleRowOnly="True" AllowFocusedRow="True" /> <SettingsLoadingPanel Mode="Disabled" /> <Columns> <dx:GridViewDataTextColumn FieldName="DeliveryReceiptID" ReadOnly="True" ShowInCustomizationForm="True" VisibleIndex="0" Caption="Rcpt #" Width="50px"> </dx:GridViewDataTextColumn> <dx:GridViewDataTextColumn FieldName="Company" ShowInCustomizationForm="True" VisibleIndex="1" Width="150px"> </dx:GridViewDataTextColumn> <dx:GridViewDataDateColumn FieldName="DeliveryDate" ShowInCustomizationForm="True" VisibleIndex="2" Width="100px" Caption="Dlvry Date"> </dx:GridViewDataDateColumn> <dx:GridViewDataTextColumn FieldName="CompanyID" ShowInCustomizationForm="True" Visible="False" VisibleIndex="3"> </dx:GridViewDataTextColumn> </Columns> </dx:ASPxGridView>

                                • Dhaval.Shah 07.20.2016
                                  Hi Barry,
                                  The reason your grid is not showing data is (I believe) it is not binding to the data in "postback" (paging, sorting, filtering) cycle of the page.
                                  Whenever you put a condition as you have, in the page_load, here is what happens:
                                  First run
                                  1. condition is true (If !Postback)
                                  2. data is bound
                                  and when you click on any other page,
                                  1. condition is false (If !Postback)
                                  2. Because DataBind statement does not get executed, DataBinding, DataBound events will also not trigger.
                                  Hope this helps.
                                • Artem (DevExpress Support) 07.21.2016

                                  Hello Barry,

                                  I've created a separate ticket on your behalf (T405800: ASPxGridView - Paging doesn't work) to process your inquiry more efficiently. It has been placed in our processing queue and will be answered shortly.

                                If you need additional product information, write to us at or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2015 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners