I have Problem with DataViewConverter that had been provided by AjaxPro
public override string Serialize(object o)
{
if(!(o is DataView))
throw new NotSupportedException();
DataView dv = (DataView)o;
DataTableConverter dtc = new DataTableConverter();
return dtc.Serialize(dv.Table);
}
public override string Serialize(object o)
{
if(!(o is DataTable))
throw new NotSupportedException();
StringBuilder sb = new StringBuilder();
DataTable dt = (DataTable)o;
DataColumnCollection cols = dt.Columns;
DataRowCollection rows = dt.Rows;
bool b = true;
sb.Append("new ");
sb.Append(clientType);
sb.Append("([");
foreach(DataColumn col in cols)
{
if(b){ b = false; }
else{ sb.Append(","); }
sb.Append('[');
sb.Append(JavaScriptSerializer.Serialize(col.ColumnName));
sb.Append(',');
sb.Append(JavaScriptSerializer.Serialize(col.DataType.FullName));
sb.Append(']');
}
sb.Append("],[");
b = true;
foreach(DataRow row in rows)
{
if(b){ b = false; }
else{ sb.Append(","); }
sb.Append(JavaScriptSerializer.Serialize(row));
}
sb.Append("])");
return sb.ToString();
}
The Question is What will happen if i have Dataview that i had been
filtered
So i make it become like this
public override string Serialize(object o)
{
if(!(o is DataView))
throw new NotSupportedException();
DataView dv = (DataView)o;
DataTableConverter dtc = new DataTableConverter();
return dtc.Serialize(dv.Table,dv);
}
public string Serialize(object o,DataView val)
{
if(!(o is DataTable))
throw new NotSupportedException();
StringBuilder sb = new StringBuilder();
DataTable dt = (DataTable)o;
DataColumnCollection cols = dt.Columns;
DataRowCollection rows = dt.Rows;
bool b = true;
sb.Append("new ");
sb.Append(clientType);
sb.Append("([");
foreach(DataColumn col in cols)
{
if(b){ b = false; }
else{ sb.Append(","); }
sb.Append('[');
sb.Append(JavaScriptSerializer.Serialize(col.ColumnName));
sb.Append(',');
sb.Append(JavaScriptSerializer.Serialize(col.DataType.FullName));
sb.Append(']');
}
sb.Append("],[");
b = true;
// foreach(DataRow row in rows)
// {
// if(b){ b = false; }
// else{ sb.Append(","); }
//
// sb.Append(JavaScriptSerializer.Serialize(row));
// }
DataRow row;
foreach (DataRowView drv in val)
{
row=drv.Row;
if(b){ b = false; }
else{ sb.Append(","); }
sb.Append(JavaScriptSerializer.Serialize(row));
}
sb.Append("])");
return sb.ToString();
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ajax.NET Professional" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/ajaxpro
The latest downloads of Ajax.NET Professional can be found at
http://www.ajaxpro.info/
Don't forget to read my blog at http://weblogs.asp.net/mschwarz/
-~----------~----~----~----~------~----~------~--~---