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

                                    [C#]
                                    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
                                7

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

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



                                Note that 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 shown 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 custom callback state. You can learn more about this mechanism here:

                                ASPxGridView Row Cache

                                Here is some code snippet:

                                [C#]
                                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(); }


                                Another potential cause of this misbehavior is non-unique key values. That is, values of fields specified via the ASPxGridView.KeyFieldName property must be unique.

                                As you see, the ASPxGridView requires data binding on every request. Unlike the standard asp:GridView control, the ASPxGridView does not store data between requests. The ViewState in ASP.NET is used to store the current state of a control. Please see the Understanding ASP.NET View State page to learn more on this subject. 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). However, the large amount of data will be transferred from the client to the server and back during every request. In addition, the server CPU time will be consumed to serialize/deserialize the stored data objects (if any). Therefore, in our ASPxGridView, the data source is not saved in the ViewState, and you need to supply a valid data source on every page request. 

                                Also, note that many other ASPxGridView settings and its state data are stored in the ViewState if the EnableViewState option is enabled. We recommend disabling this option only if you create an ASPxGridView control dynamically and 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).

                                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

                                Show all comments
                                • Harika Gandham 05.28.2012

                                  protected dataset binddata()
                                  {
                                    your sourcecode here and
                                  bind grid
                                  then return dataset
                                  }
                                  protected void page_load()
                                  {
                                  if(!ispostback)
                                  {
                                   binddata();
                                  }
                                  }

                                • 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

                                  @Daniel,

                                  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;
                                         DBRes.MakeConnection_Dotood();
                                         //int parentid = 0;
                                         //ASPxTreeList treeList = (ASPxTreeList)sender;
                                         SqlCommand objCmd = new SqlCommand();
                                         objCmd.Connection = DBRes.objConn_Dotood;
                                         //TreeListNode treeNode = treeList.FindNodeByKeyValue(key);
                                         try
                                         {
                                             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;
                                             objCmd.ExecuteNonQuery();
                                             //DataTable dt = new DataTable();
                                             //SqlDataAdapter da = new SqlDataAdapter(objCmd);
                                             //da.Fill(dt);
                                             SqlDataReader dr = objCmd.ExecuteReader();
                                             dr.Read();
                                             grid_fileDesc.DataSource = dr;
                                             grid_fileDesc.DataBind();
                                             dr.Close();
                                         }
                                         catch (Exception ex)
                                         {
                                             objCmd.CommandText = "";
                                             MessageBox.Show("алдаа гарлаа" + ex);
                                         }
                                         objCmd.Dispose();
                                     }

                                • 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....

                                  [C#]
                                  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:
                                  [C#]
                                  Page Load: if (!IsPostBack) { ASPxGridViewReceipts.DataBind(); } protected void ASPxGridViewReceipts_DataBinding(object sender, EventArgs e) { ASPxGridViewReceipts.DataSource = sdsReceipts; //sdsReceipts = SQLDataSource }

                                  [ASPx]
                                  <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 info@devexpress.com 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-2017 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners