DataRowConverter.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 DataRow object.
- /// </summary>
- public class DataRowConverter : IJavaScriptConverter
- {
- public DataRowConverter() : base()
- {
- }
-
- public override string Serialize(object o)
- {
- if(!(o is DataRow))
- throw new NotSupportedException();
-
- StringBuilder sb = new StringBuilder();
- DataRow row = (DataRow)o;
-
- DataColumnCollection cols = row.Table.Columns;
- int colcount = cols.Count;
- bool b = true;
- 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(DataRow)};
- }
- }
- }
- }