GridViewDrillDownjQueryAjax.aspx
上传用户:mengyi0109
上传日期:2021-12-08
资源大小:58k
文件大小:8k
源码类别:

Ajax

开发平台:

Java

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridViewDrillDownjQueryAjax.aspx.cs" Inherits="GridViewDrillDownjQueryAjax" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5.     <title>JQuery Demo</title>
  6.     <link type="text/css" rel="Stylesheet" href="Assets/css/dialog.css" />
  7.     <link type="text/css" rel="Stylesheet" href="Assets/css/pager.css" />
  8.     <link type="text/css" rel="Stylesheet" href="Assets/css/grid.css" />
  9.     <link type="text/css" rel="Stylesheet" href="Assets/css/subgrid.css" />
  10. </head>
  11. <body>
  12.     <form id="form1" runat="server">
  13.         <asp:ScriptManager ID="ScriptManager1" runat="server" >
  14.             <Scripts>
  15.                 <asp:ScriptReference Path="~/scripts/jquery-1.2.3.min.js" ScriptMode="Release" />
  16.             </Scripts>
  17.         </asp:ScriptManager>
  18.         <asp:SqlDataSource ID="sqlDsCustomers" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind %>"
  19.             SelectCommand="SELECT [Customers].[CustomerID], [Customers].[CompanyName], COUNT([OrderID]) TotalOrders&#13;&#10;FROM [Customers] INNER JOIN [Orders] ON [Customers].[CustomerID]=[Orders].[CustomerID]&#13;&#10;Group By [Customers].[CustomerID], [Customers].[CompanyName]">
  20.         </asp:SqlDataSource>
  21.         <div id="dlg" class="dialog" style="width: 700px">
  22.             <div class="header" style="cursor: default">
  23.                 <div class="outer">
  24.                     <div class="inner">
  25.                         <div class="content">
  26.                             <h2>
  27.                                 Northwind: Orders By Customer</h2>
  28.                         </div>
  29.                     </div>
  30.                 </div>
  31.             </div>
  32.             <div class="body">
  33.                 <div class="outer">
  34.                     <div class="inner">
  35.                         <div class="content">
  36.                             <asp:Panel CssClass="grid" ID="pnlCust" runat="server">
  37.                                 <asp:UpdateProgress AssociatedUpdatePanelID="pnlUpdate" runat="server" >
  38.                                     <ProgressTemplate>
  39.                                         <img alt="loadting" src="Assets/img/progress-indicator.gif"  />    
  40.                                     </ProgressTemplate>
  41.                                 </asp:UpdateProgress>
  42.                                 <asp:UpdatePanel ID="pnlUpdate" runat="server">
  43.                                     <ContentTemplate>
  44.                                         <asp:GridView Width="100%" AllowPaging="True" ID="gvCustomers" AutoGenerateColumns="False"
  45.                                             DataSourceID="sqlDsCustomers" runat="server" ShowHeader="False">
  46.                                             <Columns>
  47.                                                 <asp:TemplateField>
  48.                                                     <ItemTemplate>
  49.                                                         <div class="group" style="display:inline" id='<%#String.Format("customer{0}",Container.DataItemIndex) %>' 
  50.                                                             onclick='showhide(<%#String.Format(""#customer{0}"",Container.DataItemIndex) %>,
  51.                                                                               <%#String.Format(""#order{0}"",Container.DataItemIndex) %>,
  52.                                                                               <%#String.Format(""{0}"",Eval("CustomerID")) %>)'>
  53.                                                             <asp:Image ID="imgCollapsible" CssClass="first" ImageUrl="~/Assets/img/plus.png"
  54.                                                                 Style="margin-right: 5px;" runat="server" /><span class="header">
  55.                                                                     <%#Eval("CustomerID")%>:
  56.                                                                     <%#Eval("CompanyName")%>(<%#Eval("TotalOrders")%> Orders) </span>
  57.                                                         </div>                                                        
  58.                                                         <div id='<%#String.Format("order{0}",Container.DataItemIndex) %>' class="order"></div>
  59.                                                     </ItemTemplate>
  60.                                                 </asp:TemplateField>
  61.                                             </Columns>
  62.                                         </asp:GridView>
  63.                                     </ContentTemplate>
  64.                                 </asp:UpdatePanel>
  65.                             </asp:Panel>
  66.                         </div>
  67.                     </div>
  68.                 </div>
  69.             </div>
  70.             <div class="footer">
  71.                 <div class="outer">
  72.                     <div class="inner">
  73.                         <div class="content">
  74.                         </div>
  75.                     </div>
  76.                 </div>
  77.             </div>
  78.         </div>
  79.         
  80.         <div id="progress" style="position:absolute;visibility:hidden;display:inline">
  81.             <img alt="loadting" src="Assets/img/ajaxloading.gif"/>
  82.         </div>
  83.         
  84.         <script type="text/javascript">
  85.             //master: id of div element that contains the information about master data
  86.             //details: id of div element wrapping the details grid
  87.             //customerId: id of the customer to be send as parameter to web method
  88.             function showhide(master,detail,customerId)
  89.             { 
  90.                 //First child of master div is the image
  91.                 var src = $(master).children()[0].src;
  92.                 //Switch image from (+) to (-) or vice versa.
  93.                 if(src.endsWith("plus.png"))
  94.                     src = src.replace('plus.png','minus.png');
  95.                 else
  96.                     src = src.replace('minus.png','plus.png');
  97.                 //if the detail DIV is empty Initiate AJAX Call, if not that means DIV already populated with data             
  98.                 if($(detail).html() == "")
  99.                 {
  100.                     //Prepare Progress Image
  101.                     var $offset = $(master).offset();
  102.                     $('#progress').css('visibility','visible');
  103.                     $('#progress').css('top',$offset.top);
  104.                     $('#progress').css('left',$offset.left+$(master).width());                    
  105.                     //Prepare Parameters
  106.                     var params = '{customerId:"'+ customerId +'"}';                    
  107.                     //Issue AJAX Call
  108.                     $.ajax({
  109.                             type: "POST", //POST
  110.                             url: "GridViewDrillDownjQueryAjax.aspx/GetOrders", //Set call to Page Method
  111.                             data: params, // Set Method Params
  112.                             beforeSend: function(xhr) {
  113.                                 xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");},
  114.                             contentType: "application/json; charset=utf-8", //Set Content-Type
  115.                             dataType: "json", // Set return Data Type
  116.                             success: function(msg, status) {
  117.                                 $('#progress').css('visibility','hidden');
  118.                                 $(master).children()[0].src = src;
  119.                                 $(detail).html(msg);
  120.                                 $(detail).slideToggle("normal"); // Succes Callback
  121.                                 },
  122.                             error: function(xhr,msg,e){
  123.                                 alert(msg);//Error Callback
  124.                                 }
  125.                             });
  126.                 }
  127.                 else
  128.                 {
  129.                     //Toggle expand/collapse                   
  130.                     $(detail).slideToggle("normal");
  131.                     $(master).children()[0].src = src;
  132.                 }
  133.             }
  134.         </script>
  135.     </form>
  136. </body>
  137. </html>