欢迎光临
我们一直在努力

在客户端用XmlHttp取得服务器端的DataSet数据-.NET教程,数据库应用

建站超值云服务器,限时71元/月

xmlhttp.htm
<html>
 <head>
  <title>lion互动网络==》在客户端用xmlhttp取得服务器端的dataset数据</title>
  <meta http-equiv=”pragma” content=”no-cache”>
 </head>
 <body>
  <input id=”button1″ onclick=”getdataset()” type=”button” value=”取得xmlhttp.aspx中的dataset以xml形式显示”
   name=”button1″>
  <div id=”abc”><font face=”宋体”></font></div>
<script language=”jscript”>
function createxmlhttp()
{
 try{return new activexobject(msxml2.xmlhttp);}catch(x){}
 try{return new activexobject(microsoft.xmlhttp);}catch(x){}
 throw(new error(-1,不能创建xmlhttp));
}
function getdataset()

 var xmlhttp = createxmlhttp();
 var url = document.location.href;
 url = url.substring(0,url.lastindexof(“\/”)+1)+”xmlhttp.aspx”;
 xmlhttp.open(“get”,url,false)
 xmlhttp.setrequestheader(“content-type”,”text/xml”)
 xmlhttp.send()
 abc.innertext = (xmlhttp.responsexml.xml);
 
}
</script>
 </body>
</html>

xmlhttp.aspx
<%@ page language=”c#” codebehind=”xmlhttp.aspx.cs” src=”xmlhttp.aspx.cs” autoeventwireup=”false” inherits=”exam.webform1″ %>

xmlhttp.aspx.cs
using system;
using system.collections;
using system.componentmodel;
using system.data;
using system.drawing;
using system.web;
using system.web.sessionstate;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.htmlcontrols;

namespace exam
{
 /// <summary>
 /// webform1 的摘要说明。
 /// </summary>
 public class webform1 : system.web.ui.page
 {
  private void page_load(object sender, system.eventargs e)
  {   
   // 在此处放置用户代码以初始化页面
   
   system.data.datatable dt = new system.data.datatable(“temptable”);
   dt.columns.add(“id”,typeof(int));
   dt.columns.add(“name”,typeof(string));
   dt.columns.add(“addtime”,typeof(datetime));
   dt.columns[0].autoincrement = true;
   dt.columns[0].autoincrementseed = 1;
   dt.columns[0].autoincrementstep = 1;
   for(int i=0;i<20;i++)
   {
    system.data.datarow dr= dt.newrow();
    dr[1] = “欢迎光临lion互动网络,第 “+ (i+1) +” 行”;
    dr[2] = system.datetime.now.adddays(i);
    dt.rows.add(dr);
   }
   system.data.dataset ds = new system.data.dataset(“root”);
   ds.tables.add(dt);
   response.buffer=true;
   response.cachecontrol=”no-cache”;
   response.contenttype = “text/xml”;
   response.clear();
   response.write(“<?xml version=1.0 encoding=gb2312?>”);
   response.write(ds.getxml());
   response.end();
   dt.clear();
   dt.dispose();
   ds.clear();
   ds.dispose();
   
  }

  #region web 窗体设计器生成的代码
  override protected void oninit(eventargs e)
  {
   //
   // codegen: 该调用是 asp.net web 窗体设计器所必需的。
   //
 &nbsp; initializecomponent();
   base.oninit(e);
  }
  
  /// <summary>
  /// 设计器支持所需的方法 – 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void initializecomponent()
  {   
   this.load += new system.eventhandler(this.page_load);

  }
  #endregion
 }
}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 在客户端用XmlHttp取得服务器端的DataSet数据-.NET教程,数据库应用
分享到: 更多 (0)