这是index.htm
在要调用的地方写上<script src="Datagrid.aspx?id=1"></script>
然后在datagrid.aspx页面写如下的代码就可以解决这个问题了
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<
%@import namespace=System.Data%>
<
%@import namespace=System.Data.OleDb%>
<% int n;
int nn=Convert.ToInt32(Request.QueryString["id"]);
string str;
string sql ="select top 12 articleid,title,dateandtime from article where classid=5 order by dateandtime DESC ";
string conn ="provider=Microsoft.jet.oledb.4.0;data source="+Server.MapPath(ConfigurationSettings.AppSettings["MDBpath"]);
OleDbConnection myconnection = new OleDbConnection(conn);
OleDbCommand mycommand= new OleDbCommand(sql,myconnection);
myconnection.Open();
OleDbDataReader myreader;
myreader=mycommand.ExecuteReader();
switch(nn)
{
case 1:
//对str赋值
%>document.write("<%=str%>");
<%
};break;
case 2:
//对str赋值
<%
};break;
}
myreader.Close();
myconnection.Close();
%>