on 09-06-2005 8:23 PM
Hi All,
can we export the DataGrid to excel from .net iviews?. i tried with the following code it works fine in the aspx page but in the portal iview its not working, can anyone pls let me know how to go about it
here is the code i tried
Private Sub btnDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim oStringWriter As New System.IO.StringWriter
Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)
DataGrid1.RenderControl(oHtmlTextWriter)
Response.Write(oStringWriter.ToString())
Response.End()
End Sub
thanks
Murali.
Hi Murali,
Note that it should only work when the iView's isolation mode is set to URL.
Anyway, doesn't this way (putting the code in the button click) pose the problem of further navigation (after the file has downloaded)? I think a nicer UI way would be to put a url on a page which will point to the same PortalComponent, which a query parameter, and add this same code in the page load, asking for the query string. similar to what is in this "how-to":
https://media.sdn.sap.com/html/submitted_docs/dotnet/How%20to/ThirdPartyChartControl.htm
Regards,
Ofer
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Murali
Since Portal Applications are not standard asp.net Web Applications it requires some mild modification.
try the following code instead:
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
DataGrid1.RenderControl(htw);
Response.Write(sw.ToString());
Mind my (c#) lang.
You can also look at another sample of changing the response content type at https://media.sdn.sap.com/html/submitted_docs/dotnet/How%20to/Content%20Type.htm
Cheers,
Tsachi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.