Serialization

Posts   
 
    
superman
User
Posts: 11
Joined: 06-Jun-2006
# Posted on: 01-Aug-2006 20:48:08   

I'm using the adapter with LLBLGen 2.

I have several pages that have a datagrid control that is bound to entity collections. Just above the grid there are two links, "Export to Xml", "Export to Csv".

At first, I just directly serialized the collection object to xml. The problem is the resulting xml is great for web services and the like. But this is for a end user, to get just the data represented in the grid. I would prefer to xml output look more like.....

<Users> <User> <Name>Levi</Name> <UserId>superman95</UserId> </User> </Users>

So it is a much simplier format. I realize I could easily code this for a single grid. The problem is this, export concept is used all over the website. And I don't want to write custom handling for each one. Also, I want to only export the fields reflected in the grid. I could export the grid instead of the collection it is bound to. Does anyone have any suggestions?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 02-Aug-2006 02:37:04   

Creating an ability to export your grid and reusing that would be a nice bet. As far as exporting we currently export to excel using this little piece of code here. If you could do something similar for your csv and xml then that may help.

Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
mExportGrid.DataBind();
mExportGrid.Visible = true;
ClearControls(mExportGrid);
mExportGrid.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();