public class MyClass
{
[AjaxMethod]
public string GetDataSet()
{
DataSet dst = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("Text");
dt.Columns.Add("Number");
Random random = new Random(Guid.NewGuid().GetHashCode());
for (int i = 0; i < random.Next(10,20); i++)
{
DataRow row = dt.NewRow();
row["Text"] = Guid.NewGuid().ToString("N");
row["Number"] = random.Next(100);
dt.Rows.Add(row);
}
dst.Tables.Add(dt);
string text = "";
using(MemoryStream ms = new MemoryStream())
{
dst.WriteXml(ms);
ms.Position = 0;
StreamReader sr = new StreamReader(ms);
text = sr.ReadToEnd();
}
return text;
}
}
第三步:在Page_Load中註冊該方法,AjaxPro.Utility.RegisterTypeForAjax(typeof(WebTest1.AjaxTest1));(WebTest1是名稱空間的名字)