Auto expand the grid upon search... - HIGH PRIORITY

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dorandoran
    New Member
    • Feb 2007
    • 145

    Auto expand the grid upon search... - HIGH PRIORITY

    I used this article (http://www.codeproject.com/KB/webfor...dGridView.aspx) to accomplish expand/collaspe grid. I also added a search and it works. but i need to be now automatically expand the corresponded grid where search was found.

    User has to click on all the parent grid to find out which child grid has records. How can I automatically expand the grid where there are results?

    I probably need a function like below ExpandAll() which i can call right after I call this method fillsubgrid() upon clicking the search button. the following i m using for expand/collaspe.

    Code:
    function expandcollapse(obj,row)
        {
            var div = document.getElementById(obj);
            var img = document.getElementById('img' + obj);
            
       
            
            if (div.style.display == "none")
            {
                div.style.display = "block";
                if (row == 'alt')
                {
                    img.src = "minus.gif";
                }
                else
                {
                    img.src = "minus.gif";
                }
                img.alt = "Close to view other Records";
            }
            else
            {
                div.style.display = "none";
                if (row == 'alt')
                {
                    img.src = "plus.gif";
                }
                else
                {
                    img.src = "plus.gif";
                }
                img.alt = "Expand to show Records";
            }
        }
    Last edited by Frinavale; Sep 16 '09, 06:26 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Are you using Ajax (UpdatePanel's) or are you doing full page postbacks to the server?

    Comment

    • dorandoran
      New Member
      • Feb 2007
      • 145

      #3
      No ajax. I guess full page postback

      Comment

      • dorandoran
        New Member
        • Feb 2007
        • 145

        #4
        I am trying to follow this but not working.

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          You should look into using the window.onload event.

          Write a function that will handle the window's onload event and expand the grid upon successful search....

          Comment

          • dorandoran
            New Member
            • Feb 2007
            • 145

            #6
            sound good and easy. but no exposure to window onload event. let me google.

            Comment

            • dorandoran
              New Member
              • Feb 2007
              • 145

              #7
              No luck. I did not find any link that talks about how to expand grids on window. onload. please suggest.

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                You need to write a JavaScript function that expands the grids.
                Then you need to specify that this JS function should be called during the window.onload event.

                For example, say you have the following JavaScript function that expands all of the rows in the grid:

                Code:
                <script type="text/javascript>
                //<![CDATA[ 
                  function ExpandAll() {
                    var allRowElements = document.getElementsByTagName("tr");
                    var numElements = allRowElements .length;
                    for (var i = 0; i < numElements; i++) {
                      allRowElements [i].style.display = "table-row";
                    }
                  }
                  function CollapseAll() {
                    var allRowElements = document.getElementsByTagName("tr");
                    var numElements = allRowElements .length;
                    for (var i = 0; i < numElements; i++) {
                      allRowElements [i].style.display = "none";
                    }
                  }   
                //]]>
                </script>
                You would call that function during the window.onload event like:

                Code:
                <script type="text/javascript">
                //<![CDATA[
                  if(window.attachEvent){
                    window.attachEvent("onload",ExpandAll);
                  }else{
                    window.addEventListener("load",ExpandAll);
                  }
                //]]>
                </script>

                Comment

                Working...