惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
罗磊的独立博客
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Jina AI
Jina AI
V
V2EX
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
酷 壳 – CoolShell
酷 壳 – CoolShell
月光博客
月光博客
量子位
MyScale Blog
MyScale Blog
G
Google Developers Blog
M
MIT News - Artificial intelligence
L
LangChain Blog
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
有赞技术团队
有赞技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
B
Blog

博客园 - 俩醒叁醉

ASP.NET MVC 4 WebAPI. Support Areas in HttpControllerSelector SQL2000安装问题(转) sql server 2008安装需要一直重启。但重启后又没有达到效果。 为数据库中所有的用户数据表生成分页存储过程 SQL 2005 字段备注获取 __doPostBack方法解析 如何在三个月掌握三年的经验(转载&&笔记) JQuery资源网站 Cookie跨域、虚拟目录 深入分析跨域cookie的问题 CnBlogsDotText使用实例 轻松搭建博客平台-开源ASP.NET 博客Subtext 的安装 表达式目录树(源MSDN) Web 2.0 编程思想:16条法则 Control Adapter 以下代码提供查询数据库中是否存在某个值 URL Routing MVC Controllers和Forms验证 CSharp——Lambda 表达式
jQuery Ajax的使用
俩醒叁醉 · 2009-04-03 · via 博客园 - 俩醒叁醉

场景:在Gridview列表中显示有从数据库提取出来的数据,现在要通过jQuery.Ui.Dialog弹出显示每条数据的详细信息,并在弹出窗口中修改编辑。

需要处理的问题:1、将Gridview中选择记录ID提交给jQuery.Ui.Dialog

                      2、保存处理

设计思路:

为数据绑定、数据更新设计一个aspx页面专门。通过调用jQuery ajax的load方法,载入数据绑定页面进而显示绑定的数据。

页面代码

<div id="loading" class="loading">
        服务器处理中,请稍后。
    
</div>
    
<div id="divBindShowData">
    
</div>
     
<data:EntityGridView ID="GridView1" DataSourceID="TbCorpCreditsInfoDataSource"  DataKeyNames="PrimaryKey" >
       
<Columns>
          
<asp:TemplateField HeaderText="查看/编辑">
               
<ItemTemplate>
                    
<asp:HyperLink ID="hlCreditScoreEdit" runat="server"  ImageUrl='Images/View.gif'   PrimaryKey='<%# DataBinder.Eval(Container.DataItem, "PrimaryKey") %>' />
               
</ItemTemplate>
           
</asp:TemplateField>
            
<asp:BoundField DataField="CorpName" HeaderText="企业名称" SortExpression="[CorpName]" />                    
            
<asp:BoundField DataField="CreditRank" HeaderText="信用等级" SortExpression="[creditRank]" />
        
</Columns>            
      
</data:EntityGridView>

js代码

// Dialog
            $('#divBindShowData').dialog({
                autoOpen: 
false,
                width: 
800,
                height: 
550,
                modal: 
true,
                title: 
"房地产开发企业信用评价编辑",
                buttons: {
                    
"保存"function() {
                        $.ajax({
                            type: 
"Post",
                            contentType: 
"application/html",
                            url: 
"CreditIntegralListUpdate.aspx?" + $("#divBindShowData input[type='text'][Id*='data']").serialize() + "&" + $("#divBindShowData input[Id*='primaryKey']").serialize(),
                            data: 
"",
                            dataType: 
'html',
                            success: 
function(result) { alert("更新成功!"); },
                            error: 
function(result, status) { //如果没有上面的捕获出错会执行这里的回调函数
                                if (status == 'error') {   alert(status);  }
                            }
                        });
                    },
                    
"取消"function() {
                        $(
this).dialog("close");
                    }
                }
            });
            
//
            $("a[Id*='hlCreditScoreEdit']").click(function() {
                $(
"#divBindShowData").load("CreditIntegralEdit.aspx?PrimaryKey=" + $(this).attr("PrimaryKey");
                $(
'#divBindShowData').dialog('open');
                
return false;
            });
            
//对与Ajax的监控,本身是全局性的
            $(document).ready(function() {
                $(
'#loading').ajaxStart(function() {
                    $(
this).show();
                    $(
this).floatdiv("middle");
                }).ajaxStop(
function() {
                    $(
this).hide();
                });
            });
        });

这里我通过.load 方法载入了CreditIntegralEdit.aspx页面的数据,而通过数列表CreditIntegralEdit.aspx中所有需要更新的字段,并将这序列化字符串通过ajax传递给CreditIntegralListUpdate.aspx页面。从而实现数据的绑定更新。