Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Familiar Sight
 
Join Date: Feb 2007
Posts: 142
#1: Sep 16 '09
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.

Expand|Select|Wrap|Line Numbers
  1. function expandcollapse(obj,row)
  2.     {
  3.         var div = document.getElementById(obj);
  4.         var img = document.getElementById('img' + obj);
  5.  
  6.  
  7.  
  8.         if (div.style.display == "none")
  9.         {
  10.             div.style.display = "block";
  11.             if (row == 'alt')
  12.             {
  13.                 img.src = "minus.gif";
  14.             }
  15.             else
  16.             {
  17.                 img.src = "minus.gif";
  18.             }
  19.             img.alt = "Close to view other Records";
  20.         }
  21.         else
  22.         {
  23.             div.style.display = "none";
  24.             if (row == 'alt')
  25.             {
  26.                 img.src = "plus.gif";
  27.             }
  28.             else
  29.             {
  30.                 img.src = "plus.gif";
  31.             }
  32.             img.alt = "Expand to show Records";
  33.         }
  34.     }

Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,168
#2: Sep 16 '09

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


Are you using Ajax (UpdatePanel's) or are you doing full page postbacks to the server?
Familiar Sight
 
Join Date: Feb 2007
Posts: 142
#3: Sep 16 '09

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


No ajax. I guess full page postback
Familiar Sight
 
Join Date: Feb 2007
Posts: 142
#4: Sep 16 '09

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


I am trying to follow this but not working.
http://www.codeproject.com/Messages/...lapse-all.aspx
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,168
#5: Sep 16 '09

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


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....
Familiar Sight
 
Join Date: Feb 2007
Posts: 142
#6: Sep 16 '09

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


sound good and easy. but no exposure to window onload event. let me google.
Familiar Sight
 
Join Date: Feb 2007
Posts: 142
#7: Sep 25 '09

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


No luck. I did not find any link that talks about how to expand grids on window. onload. please suggest.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,168
#8: Sep 25 '09

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


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:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript>
  2. //<![CDATA[ 
  3.   function ExpandAll() {
  4.     var allRowElements = document.getElementsByTagName("tr");
  5.     var numElements = allRowElements .length;
  6.     for (var i = 0; i < numElements; i++) {
  7.       allRowElements [i].style.display = "table-row";
  8.     }
  9.   }
  10.   function CollapseAll() {
  11.     var allRowElements = document.getElementsByTagName("tr");
  12.     var numElements = allRowElements .length;
  13.     for (var i = 0; i < numElements; i++) {
  14.       allRowElements [i].style.display = "none";
  15.     }
  16.   }   
  17. //]]>
  18. </script>
  19.  
You would call that function during the window.onload event like:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. //<![CDATA[
  3.   if(window.attachEvent){
  4.     window.attachEvent("onload",ExpandAll);
  5.   }else{
  6.     window.addEventListener("load",ExpandAll);
  7.   }
  8. //]]>
  9. </script>
Reply