日期:2014-05-17 浏览次数:20505 次
<%@ Page Language="C#" debug="true"%> <%@ Import Namespace="System.Data" %> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { bool isAJAXPost = IsAJAXPost(); if (isAJAXPost)//是 { Response.Write("AJAX PostBack Data\nName:" + Request.Form["name"] + "\nNumber:" + Request.Form["number"] + "\nServerTime:" + DateTime.Now.ToString());//提供给ajax对象使用的信息 Response.End();//结束下面程序的执行 } if (!IsPostBack) { GridView1.DataSource = BuildGridViewDataSource(); GridView1.DataBind(); } } /// <summary> /// 是否是ajaxpost回来的数据,并根据数据更新表什么的 /// </summary> /// <returns>是否是ajax提交的数据</returns> private bool IsAJAXPost() { string Up = Request.Form["up"]; if (Up == "up")//此参数执行是否是ajax post回来的 { string Name = Request.Form["name"]; string Number = Request.Form["Number"]; //下面可以执行你的更新操作什么的 //====== //====== return true;//返回 } return false; } /// <summary> /// 用来做例子中的数据源 /// </summary> /// <returns></returns> private DataTable BuildGridViewDataSource() { DataTable dt = new DataTable(); dt.Columns.Add("Number"); dt.Columns.Add("Name"); DataRow dr = dt.NewRow(); dr["Number"] = "1000"; dr["Name"] = "张三"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["Number"] = "1001"; dr["Name"] = "李四"; dt.Rows.Add(dr); return dt; } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //实现单击时确发编辑 //e.Row.Attributes.Add("onclick", "OnClickedRow('" + e.Row.RowIndex + "');"); //实现双击时确发编辑 e.Row.Attributes.Add("ondblclick", "OnClickedRow(this);"); } } </script> <html> <head></head> <body> <form runat="server"> <asp:GridView Width="500" ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound"> <Columns> <asp:BoundField DataField="Number" HeaderText="编号" /> <asp:BoundField DataField="Name" HeaderText="姓名" /> </Columns> </asp:GridView> </form> <script type="text/javascript"> var FocusTR=null; function createObj() { var o=null; if(typeof(XMLHttpRequest)!="undefined") return new XMLHttpRequest();//ie7和w3c if(window.ActiveXObject)//ie6- { var MSXML=["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHTTP"]; for(var i=0;i<MSXML.length;i++) { try { o= new ActiveXObject(MSXML[i