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?

                                You must  log in  or  register  to leave comments

                                1 Solution


                                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

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

                                You must  log in  or  register  to leave comments

                                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, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

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