以下在.net1.1中通過.
1.添加對AjaxPro.dll的引用
2.在web.config 中的<system.web>中添加配置:
<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>
</httpHandlers>
2.程式中:
以下示範從資料庫中取出資料,並在前台顯示出表中的第一個儲存格的資料。
DataDemo.aspx.cs:
private void Page_Load(object sender, System.EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(DataDemo));
}
[AjaxPro.AjaxMethod]
public DataSet GetDataSet()
{
string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "DB\\AjaxDemo.mdb";
OleDbConnection con = new OleDbConnection(conStr);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter("select * from student",conStr);
da.Fill(ds);
return ds;
}
DataDemo.aspx:<script>
function showData()
{
var dataSrc = AjaxProDemo.DataDemo.GetDataSet();
var cols = dataSrc.value.Tables[0].Columns.length;
var rows = dataSrc.value.Tables[0].Rows.length;
alert(cols + " cols and " + rows + " rows");
}
function showAll()
{
var dataSrc = AjaxProDemo.DataDemo.GetDataSet();
var cell = dataSrc.value.Tables[0].Rows[1].sname;
alert(cell);
}
</script>
//
<INPUT type="button" value="ShowData" onclick="showData()">
<INPUT type="button" value="ShowAll" onclick="showAll()">
如果資料來源是對象數組,那就請看下面的代碼:
var arrStaffsSearchResult = StaffSelecter.SearchStaffs(sSearchKeyword);
lstUnSelectedStaffList.options.length = 0;
if(arrStaffsSearchResult.value==null || arrStaffsSearchResult.value.length==0)
return;
for(var i=0;i<arrStaffsSearchResult.value.length;i++)
{
var currStaffs = arrStaffsSearchResult.value[i];
var oNewItem = document.createElement("OPTION");
oNewItem.value = currStaffs.ID;
oNewItem.text = "[" + currStaffs.StaffNo + "]" + currStaffs.Name;
lstUnSelectedStaffList.add(oNewItem);
lstUnSelectedStaffList.selectedIndex = 0;
currConditionAllStaffsObj.Add(oNewItem.value,currStaffs);
}