因為項目中只能用.net 1.1,所以atlas是用不了了,只能玩玩AjaxProfession.net, 下面是一個查詢的案例。 在頁面上放置一個DataGrid1,各種查詢結果均放入其中,在client端的JS中將SQL語句傳給server端的方法,執行一個查詢,並可以控制雙擊行是否展開一個新的查詢。可將DataGrid1的內容導出到excel中、模擬gmail的Ajax的loading運用
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;
using System.Data.SqlClient;
using System.IO;
namespace eol
{
/**//// <summary>
/// index 的摘要描述。
/// </summary>
public class index : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected WebControlLibrary.InputCalendar startTime;
protected WebControlLibrary.InputCalendar endTime;
protected WebControlLibrary.InputCalendar pStartTime;
protected WebControlLibrary.InputCalendar pEndTime;
protected System.Data.SqlClient.SqlConnection Conn=new SqlConnection();
protected System.Web.UI.WebControls.TextBox eformsn;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DataGrid DataGrid1=new DataGrid();
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.HtmlControls.HtmlInputText applicant;
public string toExcel;
private void Page_Load(object sender, System.EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(eol.index));
}
public DataSet DB(string dataName, string sqlCmd)
{
string connStr="server=172.16.0.120;uid=msikdb;pwd=dbmsik;database="+dataName;
Conn.ConnectionString=connStr;
try
{
Conn.Open();
}
catch(Exception ex)
{
Conn.Close();
Response.Write(ex.Message);
}
SqlCommand cmd=new SqlCommand(sqlCmd, Conn);
SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand=cmd;
DataSet ds = new DataSet();
da.Fill(ds);
Conn.Close();
return ds;
}
Web Form 設計工具產生的程式碼#region Web Form 設計工具產生的程式碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 此為 ASP.NET Web Form 設計工具所需的呼叫。
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// 此為設計工具支援所必須的方法 - 請勿使用程式碼編輯器修改
/// 這個方法的內容。
/// </summary>
private void InitializeComponent()
{
this.Conn = new System.Data.SqlClient.SqlConnection();
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.DataGrid1.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.getPageIndexStyle);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void getPageIndexStyle(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Pager)
{
e.Item.Cells[0].Text="Total Row:"+this.DataGrid1.Items.Count.ToString();
}
}
[AjaxPro.AjaxMethod]
public string AjaxData(string sSql, bool clientEvent)
{
if (clientEvent)
{
DataGrid1.ItemDataBound+=new DataGridItemEventHandler(DataGrid1_ItemDataBound);
}
// DataGrid1.AllowPaging=true;
// DataGrid1.PagerStyle.Position=PagerPosition.Top;
// DataGrid1.PagerStyle.Mode=PagerMode.NumericPages;
// DataGrid1.ItemCreated+=new DataGridItemEventHandler(getPageIndexStyle);