This example illustrates how to bind ASPxGridView to data when clicking an external button.
Note that if the grid is already bound to another datasource, it is necessary to set the grid's EnableViewState property to False.
Also, clear the grid's columns and set the AutoGenerateColumns property to True before calling the DataBind method.
Question Comments
Added By: Yan Xiaohua at: 9/29/2015 11:30:16 PM
What shall we do if the source table structure may change ? e.g: click button1 return product list, but click button2, return customer list?
Added By: Jenny (DevExpress Support) at: 9/30/2015 12:45:24 AMHello Yan,
To process your recent post more efficiently, I created a separate ticket on your behalf: T295150: ASPxGridView - How to implement the approach from E4427 example if datasource can be changed. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.
This may not be the right place to ask my question, but still I am also trying to perform same operations. On click of button I am binding the data from databale to Gridview. I have enabled the sorting using
[ASPx]<SettingsBehaviorAllowSort="true"SortMode="DisplayText"/>
When I click on column header, it sots but nothing is displayed on gridview. Only on click of button it display the sorted data. From this thread I learnt that, on gridview databinding event we have to bind the grid view once again like shown below.
Is my understanding correct? Is this is the only way to rebind the gridview or any better way do you suggest. Thanks.[C#]protectedvoidASPxGridView1_DataBinding(objectsender,EventArgse){grid.DataSource=(DataTable)ViewState["testdata"];}