Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

Can I have grid-view in my web-service so that I render it on some values and create Gridview then finally send it as mail attachment in HTML format.

So basically can I place a gridview in my webservice like I do in aspx page.

note: I need not to show gridview as its a service I only want to send that format as HTML file as an attachment in mail ( I HAVE ALREADY DONE THIS IN AN ASPX PAGE IN ASP.NET)


Thanks,
Abhishek Singh.
Posted
Comments
thatraja 2-May-14 6:45am    
That's really a bad idea. Why?
abhishek.singh.valeteck 2-May-14 7:58am    
I want my grids on reports to be rendered in same way after some calculations as I did in web app so that I can send it as attachment later on.
I can attach code to support my view
thatraja 2-May-14 9:31am    
Include the code in your question

not sure that you can render control programmatically inside wcf service or not. What you can do is create HTML based on your data like below.

assume you have datatable then
C#
public static string ConvertDataTableToHTML(DataTable dt)
{
    string html = "<table>";
    //add header row
    html += "<tr>";
    for(int i=0;i<dt.columns.count;i++)>
        html+="<td>"+dt.Columns[i].ColumnName+"</td>";
    html += "</tr>";
    //add rows
    for (int i = 0; i < dt.Rows.Count; i++)
    {
        html += "<tr>";
        for (int j = 0; j< dt.Columns.Count; j++)
            html += "<td>" + dt.Rows[i][j].ToString() + "</td>";
        html += "</tr>";
    }
    html += "</table>";
    return html;
}


As per This question answers[^]
you can try by turning on ASP.NET compatibility mode in your WCF configuration.
 
Share this answer
 
v2
Crate a GridView dynamically and return it as appropriate.
For e.g.
C#
Dim mygrid As New GridView
mygrid.DataSource = New Integer() {1, 2, 3, 4, 5}
mygrid.DataBind()
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900