在WCF服务中创建gridview [英] Creating gridview inside WCF service
问题描述
我可以在网络服务中使用网格视图,以便在某些值上渲染它并创建Gridview,然后最终将其作为邮件附件发送HTML格式。
所以基本上我可以像在aspx页面一样在我的网络服务中放置一个gridview。
注意:我不需要将gridview显示为它的服务我只想将该格式作为HTML文件发送为邮件附件(我已经在ASP.NET的ASPX页面中完成了这个)
谢谢,
Abhishek Singh。
not not确保您可以在wcf服务内以编程方式呈现控件。您可以做的是根据您的数据创建HTML,如下所示。
假设您有数据表然后
public static string ConvertDataTableToHTML(DataTable dt )
{
string html = <表>跨度>;
// 添加标题行
html + = < tr>;
for ( int i = 0 ; i< dt.columns.count; i ++)>
html + = < td> + dt.Columns [i] .ColumnName + < / TD> 中跨度>;
html + = < / tr>;
// 添加行
for ( int i = 0 ; i < dt.Rows.Count; i ++)
{
html + = < TR GT&;跨度>;
for ( int j = 0 ; j< dt.Columns.Count; j ++)
html + = < td> + dt.Rows [i] [j] .ToString()+ < / td> 跨度>;
html + = < / tr>;
}
html + = < / table>;
return html;
}
动态创建一个GridView并根据需要返回它。
例如
Dim mygrid As New GridView
mygrid.DataSource = New Integer(){ 1 , 2 , 3 , 4 , 5 }
mygrid.DataBind()
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.
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
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.
Crate a GridView dynamically and return it as appropriate.
For e.g.
Dim mygrid As New GridView mygrid.DataSource = New Integer() {1, 2, 3, 4, 5} mygrid.DataBind()
这篇关于在WCF服务中创建gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!