`
zendj
  • 浏览: 116206 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

AJAXPRO.NET中使用自定类型集合的方法

阅读更多

AJAXPRO.NET中使用自定类型集合的方法

类1:

public class QQFriend
{
private int userID;
private string userName;
private string nickName;
public QQFriend()
{
}
public QQFriend(int userID,string userName,string nickName)
{
this.userID = userID;
this.userName = userName;
this.nickName = nickName;
}
public int UserID
{
get{return this.userID;}
set{this.userID = value;}
}
public string UserName
{
get{return this.userName;}
set{this.userName = value;}
}
public string NickName
{
get{return this.nickName;}
set{this.nickName = value;}
}
}

Web窗体类:

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 CeduuNew
{
public class WebForm1 : CEDUU.Common.PageBase
{
private void Page_Load(object sender, System.EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(CeduuNew.WebForm1));
AjaxPro.Utility.RegisterTypeForAjax(typeof(CeduuNew.Common.QQFriend));
}

[AjaxPro.AjaxMethod]
publicArrayList GetQQFriendList()
{
ArrayList fl = new ArrayList();
fl.Add(new Common.QQFriend(1,"laijames","James"));
fl.Add(new Common.QQFriend(2,"chen","chen1"));
return fl;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

}
}

aspx页面:

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="CeduuNew.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script language="javascript">
function getUserDefineType()
{
CeduuNew.WebForm1.GetQQFriendList(myCallbackUserDefineType);

}
function myCallbackUserDefineType(res)
{
var friendlist = res.value;
for(i=0;i<friendlist.length;i++)
{
friend = friendlist[i];
alert("userID:" + friend.UserID + "\r\n" + "UserName:" + friend.UserName + "\r\n" + "NickName:" + friend.NickName);
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<INPUT style="Z-INDEX: 102; LEFT: 112px; POSITION: absolute; TOP: 192px" onclick="getUserDefineType()"
type="button" value="服务器返回自定义数据类型">
</form>
</body>
</HTML>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics