Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
950
WebGrid with Menu
posted

Hi,

I have a webgrid and a menu (UltraWebListbar).

The menu is loaded dynamically from the SQL Server on Page_Load.
When the user clicks an item in the menu, a function (LoadGrid) is called that executes a Stored Procedure which in turn fills the grid.
For example, if the user clicked on the item "Customer" it loads the Stored Procedure "Customer_LOAD" which fills a DataSet and the grid.DataSource is assigned to that DataSet.

My question is how can use paging, filtering and sorting in this case that I cannot use the Initialize_Datasource to set the datasource every time as the Initialize_Datasource event fires first.

Note that when a menu item is clicked the code goes first through Initialize_Datasource (in my case an empty function), then from Page_Load and then it passes from Menu_ItemClicked.

 

Regards,

Nicolas

Parents
No Data
Reply
  • 45049
    posted

    My suggestion is to store information about what data you're displaying in the grid in some way that will persist across postbacks, such as a hidden field on the page or a Session variable.

    In your listbar's ItemClicked event, you'd update the value to whatever is appropraite to the item selected, then explicitly bind the grid to the corresponding data.  This is the logic that changes what data will be displayed, and also stores the right identifier for later use.

    In your grid's InitializeDataSource event, you'd read this value so that you can load the appropriate data into the grid's data source - remember that you don't need to explicitly call the grid's DataBind() method here.  Fetching data here is particularly important if you're allowing updates to your WebGrid, moreso if you're using the grid's AJAX capabilities.  This is the logic that will ensure that the grid fetches the correct data on subsequent callbacks, based on the identifier stored in the listbar's ItemClicked event.

    If the data you were retrieving was small (which I suspect isn't the case in your scenario), you could probably store the entire DataSet in a Session variable, which you'd simply retrieve in your grid's InitializeDataSource event.  Otherwise, you may only need to store enough information to uniquely identify what data you're loading.

Children
No Data