﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - WebGrid Enterprise - How to retain the loaded no of records across refreshing the grid</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-retain-the-loaded-no-of-records-across-refreshing-the-grid/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>How to retain the loaded no of records across refreshing the grid</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-retain-the-loaded-no-of-records-across-refreshing-the-grid/</link><pubDate>Sun, 02 Oct 2011 06:19:11 GMT</pubDate><dc:creator>yudi</dc:creator><description>&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt"&gt;Apologize for the delay in sending this.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt"&gt;Please follow the step-by-step below in order to implement you required scenario.&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;&lt;li style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt"&gt;Create grid, assign DataSource, DataMember and RetrieveStructure as shown in the CustomVirtualLoad.aspx tutorial file. The tutorial file is available at WebGrid Tutorial project inside the V3.5 folder.&lt;/li&gt;&lt;li style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt"&gt;In the attached sample file, the value of VirtualPageSize property is set to “10”.&lt;/li&gt;&lt;li style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt"&gt;Add an ASP.NET HiddenField control, HiddenField1, into the page. This control is used to store the total loaded rows of WebGrid. &lt;pre&gt;&amp;lt;asp:HiddenField ID="HiddenField1" runat="server" /&amp;gt;&lt;/pre&gt;&lt;/li&gt;&lt;li style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt"&gt;Add OnBeforeRequest client-side event of WebGrid. This event specifies the client-side function to be invoked when a request action to server is about to be made. Within this event, the value of HiddenField1 control is set based on the value of the action parameter. &lt;pre&gt;function WebGrid1_OnBeforeRequest(controlId, action) {
    var WebGrid1 = ISGetObject(controlId);
    var hf = document.getElementById("HiddenField1");
            
    if (action == "More") {
        if (hf.value != "")
            hf.value = parseInt(hf.value) &amp;#43; 10;
        else
            hf.value = WebGrid1.TotalLoadedRows &amp;#43; 10;
    }
            
    return true;
}&lt;/pre&gt;&lt;/li&gt;&lt;li style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt"&gt;Invoke the InitializePostBack server side event. &lt;pre&gt;protected void WebGrid1_InitializePostBack(object sender, PostbackEventArgs e)
{
    if (HiddenField1.Value != "")
    {
        WebGrid1.LayoutSettings.VirtualPageSize = int.Parse(HiddenField1.Value);
        WebGrid1.VirtualLoadArgs.RequestedRows = int.Parse(HiddenField1.Value);
    }

    if (e.Action == "More")
    {
        WebGrid1.RebindDataSource();
        ISNet.WebUI.FunctionParameter[] total = new ISNet.WebUI.FunctionParameter[1];
        total[0] = new ISNet.WebUI.FunctionParameter(WebGrid1.VirtualLoadArgs.TotalDataSourceRows.ToString(), "string");
        WebGrid1.ClientAction.InvokeScript("SetTotal", total);
    }

    else if (e.Action == "ColumnSort")
    {
        WebGrid1.RebindDataSource();
        ISNet.WebUI.FunctionParameter[] total = new ISNet.WebUI.FunctionParameter[1];
        total [0] = new ISNet.WebUI.FunctionParameter(WebGrid1.VirtualLoadArgs.TotalDataSourceRows.ToString(),"string");
        WebGrid1.ClientAction.InvokeScript("SetTotal",total);
    }
}&lt;/pre&gt;&lt;/li&gt;&lt;li style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt"&gt;Attach a client-side event on OnAfterResponse event. The event is used to set the value of TotalLoadedRows property of WebGrid based on the value stored in HiddenField1 control. &lt;pre&gt;function WebGrid1_OnAfterResponseProcess(controlId, actionName, lastRequestObject, xmlResponseObject) {
    var WebGrid1 = ISGetObject(controlId);
    var hf = document.getElementById("HiddenField1");
    var table = WebGrid1.RootTable;

    WebGrid1.TotalLoadedRows = hf.value;

    return true;
}&lt;/pre&gt;&lt;/li&gt;&lt;li style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt"&gt;Add SetTotal JavaScript function. This function is used to synchronize the loaded indicator shown in the status bar of WebGrid. &lt;pre&gt;function SetTotal(total) {
    var WebGrid1 = ISGetObject("WebGrid1");
    var hf = document.getElementById("HiddenField1");

    if (hf.value != "")
        WebGrid1.GetElement(WG40.STATUSBAR, WG40.HTMLROW).childNodes[3].innerText = "Loaded " &amp;#43; hf.value &amp;#43; " of " &amp;#43; total;
}&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt"&gt;A simple sample is enclosed as attachment. Please have the sample tested on your end and let us know whether this helps or not.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>How to retain the loaded no of records across refreshing the grid</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-retain-the-loaded-no-of-records-across-refreshing-the-grid/</link><pubDate>Thu, 15 Sep 2011 02:36:00 GMT</pubDate><dc:creator>Skgrid@intersoftpt.com</dc:creator><description>&lt;p&gt;Hi Yudi,&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Thanks for the response.&lt;/p&gt;
&lt;p&gt;1. First time it is working fine, but the next time it is populating the alert message saying that "Please wait while WebGrid is in progress processing request..."&lt;/p&gt;
&lt;p&gt;2. After loading (retaining) all the record, I need to retain the selection of the item, so it should not be deselected.&lt;/p&gt;
&lt;p&gt;3. How to pass value between &lt;span style="font-size: 13px"&gt;WebGrid1_InitializeDataSource to &lt;span style="font-size: 13px"&gt;WebGrid1_InitializeLayout event and vice versa.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 13px"&gt;&lt;span style="font-size: 13px"&gt;My approach to retain the no. of loaded items and item selection is:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 13px"&gt;&lt;span style="font-size: 13px"&gt;* Hold &lt;span style="font-size: 13px"&gt;WebGrid1.VirtualLoadArgs.RequestedRows from &lt;span style="font-size: 13px"&gt;WebGrid1_InitializeDataSource&lt;/span&gt; event when "Load More" action is performed&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 13px"&gt;&lt;span style="font-size: 13px"&gt;&lt;span style="font-size: 13px"&gt;* Set the value to &lt;span style="font-size: 13px"&gt;e.Layout.VirtualPageSize in &lt;span style="font-size: 13px"&gt;WebGrid1_InitializeLayout event&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 13px"&gt;&lt;span style="font-size: 13px"&gt;&lt;span style="font-size: 13px"&gt;&lt;span style="font-size: 13px"&gt;So that the next time "Refresh" is called, that value will be set to VirtualPageSize hence it will load the same no. of records at once, instead of calling it multiple times.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</description></item><item><title>How to retain the loaded no of records across refreshing the grid</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-retain-the-loaded-no-of-records-across-refreshing-the-grid/</link><pubDate>Wed, 14 Sep 2011 22:06:21 GMT</pubDate><dc:creator>yudi</dc:creator><description>&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt;"&gt;It is the default of WebGrid that when user clicks the “Refresh” button, WebGrid will invoke InitializeDataSource event and load the initial number of records.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt;"&gt;In order to implement your scenario, I’d like to suggest you to utilize the OnBeforeRequest client-side event. OnBeforeRequest specifies the client-side function to be invoked when a request action to server is about to be made.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt;"&gt;It has two parameters: controlId and action. The controlId is the ID of WebGrid that fires this client-side event and the action is the request action of WebGrid to the server.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt;"&gt;When user loads more data, the value of action property is “More”; and when user clicks the refresh button, the value of action property is “Refresh”. A global variable is added to store the number of “More” action each time user loads more data. This variable is incremented every time user loads more data.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt;"&gt;Next, invoke wgLoadMore method to load more data for n times (the n times is equal to the number of “More” action count). A delay – window.setTimeOut – needed to let WebGrid finish its request before starting a new request.&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&amp;lt;script type="text/javascript"&amp;gt;
	&amp;lt;!--
    var loadmore = 0;

    function WebGrid1_OnBeforeRequest(controlId, action) {
        var WebGrid1 = ISGetObject(controlId);

        if (action == "More")
            loadmore += 1;
        if (action == "Refresh") {
            for (var i = 0; i &amp;lt; loadmore; i++) {
                window.setTimeout(function () {
                    wgLoadMore(controlId);
                }, 2000);
            }
        }

        return true;
    }
	--&amp;gt;
&amp;lt;/script&amp;gt;&lt;/pre&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt;"&gt;Hope this helps.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>How to retain the loaded no of records across refreshing the grid</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-retain-the-loaded-no-of-records-across-refreshing-the-grid/</link><pubDate>Tue, 13 Sep 2011 07:47:47 GMT</pubDate><dc:creator>Skgrid@intersoftpt.com</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;There are 100's of records in the grid, but we are loading first 50 records bydefault, when user clicks on "Load more data" icon from the grid taskbar, we are loading another set of 50 records.&lt;/p&gt;
&lt;p&gt;If I click on "Load more data" icon from the grid taskbar 3 times, it load 200 records, now if I refresh the grid I want to retain the same no. of records (i.e., 200), but the InitializeDataSource event fires, and it load the first 50 records.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Kindly suggest the solution.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Thanks in advance&lt;/p&gt;</description></item></channel></rss>