views:

837

answers:

2

For the following code

<asp:GridView runat="server" ID="gvCustomers" ...
...
 <Columns>
   <asp:TemplateField>
     <HeaderTemplate>
     </HeaderTemplate>
     <ItemTemplate>
       <asp:ImageButton runat="server" ID="ITimgExpand" ImageUrl="~/Images/Common/expand.gif" CommandName="Select" />
     </ItemTemplate>
   </asp:TemplateField>
   ...
   <asp:TemplateField>
     <ItemTemplate>
      </td></tr>
        <tr>
           <td colspan="3">
              <div id="document_<%# Eval("RENTER_ID") %>" style="margin:10; display: none; position: relative">
                  <asp:GridView ID="gvDocuments" runat="server" ...
         ...

How does one expand/collapse div which includes nested GridView while clicking ITimgExpand ImageButton?

A: 

Use can use the Jquery hide function to do this.

http://jqueryui.com/demos/hide/#default

Tony Borf
+2  A: 

Add the following javascript function:

function togglePanel(divId){
  if (document.getElementById){
    var container = document.getElementById(divId);
    if (container.style.display =='none'){
      container.style.display = 'block';    
    }else{
      container.style.display ='none';
    }    
  }
}

Then have your ImageButton call the function passing the ID of the

<asp:imagebutton id="ImgBtn" runat="server" onclientclick="togglePanel('document_<%# Eval("RENTER_ID") %>')" />
Michael M
While doing this, div display property will be reset after postback to be 'display: none' as nested grid being binded after selecting row.
Ahmed
Are you doing anything on postback?
Michael M
I believe if you just return false from the function it should prevent the postback.
Michael M
Yes, there is postback to fetch data for nested grid.Nested grid to be binded after postback.
Ahmed
Since you need to post back, there's two ways you can do this. First, on postback, you can get the div and manually alter the style attributes to set display. The other option is to use a DataList and then place your expanded content in the SelectedItemTemplate.
Michael M
Use a property in the viewstate to hold the state of that particular image click and then call it in javascript on window load.
Joel Etherton