DataRowViewConverter.cs
上传用户:szgaoree
上传日期:2009-01-05
资源大小:74k
文件大小:1k
- using System;
- using System.Text;
- using System.Data;
- namespace AjaxPro
- {
- /// <summary>
- /// Provides methods to serialize and deserialize a DataRowView object.
- /// </summary>
- public class DataRowViewConverter : IJavaScriptConverter
- {
- private string clientType = "Ajax.Web.DataRow";
- public DataRowViewConverter() : base()
- {
- }
- public override string Serialize(object o)
- {
- if(!(o is DataRowView))
- throw new NotSupportedException();
-
- StringBuilder sb = new StringBuilder();
- DataRowView row = (DataRowView)o;
-
- DataColumnCollection cols = row.DataView.Table.Columns;
- int colcount = cols.Count;
- bool b = true;
- sb.Append("new ");
- sb.Append(clientType);
- sb.Append("([");
-
- for(int i=0; i<colcount; i++)
- {
- if(b){ b = false; }
- else{ sb.Append(","); }
- sb.Append(JavaScriptSerializer.Serialize(row[cols[i].ColumnName]));
- }
- sb.Append("])");
- return sb.ToString();
- }
- public override Type[] SerializableTypes
- {
- get
- {
- return new Type[]{typeof(DataRowView)};
- }
- }
- }
- }