c# asp:UpdatePanel 和 asp:Repeater实现页面局部数据无刷新取得

 一、首先在web.config文件中添加如下内容。(不添加下面的内容实现不了刷新局部页面的效果)

    <httpHandlers>       
      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
    </httpHandlers>


二、 <asp:SrciptManager> 控件一定要紧跟在<form>后面

三、bin文件夹里必须有下面三个文件的引用

他们所在的文件夹位置是
C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025

AJAXExtensionsToolbox.dll
System.Web.Extensions.Design.dll
System.Web.Extensions.dll

四、测试代码文件如下:

    .cs文件load事件代码

protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            System.Threading.Thread.Sleep(2000);//延迟响应时间
        }
        DataTable dt = new DataTable();
    
        dt.Columns.Add(new DataColumn("Name"));
        dt.Columns.Add(new DataColumn("sex"));
        dt.Columns.Add(new DataColumn("DateTime"));
        for (int i = 0; i < 5; i++) {
            DataRow dr = dt.NewRow();
            dr["Name"] = "http://www.my400800.cn";
            dr["sex"] = "男";
            dr["DateTime"] = Convert.ToString(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            dt.Rows.Add(dr);
        }


        gv_detailList.DataSource = dt;
        gv_detailList.DataBind();
    }

.aspx文件内容

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridViewDrillDownjQueryAjax.aspx.cs" Inherits="GridViewDrillDownjQueryAjax" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>JQuery Demo(http://www.my400800.cn)</title>   
</head>
<body>
    <form id="form1" runat="server">

 <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>

  
        <asp:UpdateProgress ID="listDetailPress" runat="server" AssociatedUpdatePanelID="UpdatePanelGridDetail" >
            <ProgressTemplate>
                <img src="../../img/progress-indicator.gif" />数据加载中,请稍后
            </ProgressTemplate>
        </asp:UpdateProgress>
     
        <asp:UpdatePanel ID="UpdatePanelGridDetail" runat="server">
            <ContentTemplate>
                <asp:Repeater ID="gv_detailList" runat="server">
                <HeaderTemplate>
                <table style="width: 100%">
                </HeaderTemplate>
                    <ItemTemplate>
                        <tr>
                            <td rowspan="3" style="width: 10%">
                            </td>
                            <td style="text-align: left">
                                <%#Eval("Name").ToString()%></td>
                            <td rowspan="3" style="width: 100px">
                                <%#Eval("Sex").ToString()%>
                            </td>
                        </tr>
                        <tr>
                            <td style="height: 18px; text-align: left;">
                                Summary</td>
                        </tr>
                        <tr>
                            <td>
                               
                                    发送时间<%#Eval("DateTime").ToString()%>  来源 评价
                            </td>
                        </tr>
                    </ItemTemplate>
                    <FooterTemplate>
                    </table>
                   
                
                  <asp:LinkButton ID="LinkButton1" runat="server" >刷新</asp:LinkButton>
                    </FooterTemplate>
                </asp:Repeater>
            </ContentTemplate>
        </asp:UpdatePanel>

    </form>
</body>
</html>

你可能感兴趣的:(update)