我在后面的代码中有以下内容:
[WebMethod]
public static string GenerateHtml(string id)
{
//return id;
DataView vwMain2;
try
{
DbProviderFactory dbf = DbProviderFactories.GetFactory();
using (IDbConnection con = dbf.CreateConnection())
{
string sSQL;
sSQL = "select top 20 " + ControlChars.CrLf
+ " ASSISTING_FILE_ID, DATE_ENTERED, CLIENT_CLAIM_NUM, PRIMARY_INSURED, PRIMARY_CLAIMANT, LOB_ID, FILE_STATUS, BRANCH_NAME," + ControlChars.CrLf
+ " OWNERS_FIRST_NAME, OWNERS_LAST_NAME, OWNERS_NAME, OWNERS_EMAIL, OWNERS_OFFICE_PHONE, OWNERS_FAX_PHONE, OWNERS_CELL_PHONE" + ControlChars.CrLf
+ " from vwFILES_DetailViewWithOwners" + ControlChars.CrLf
+ " where 1 = 1 " + ControlChars.CrLf;
//+ " where 1 = 1 and WEB_USER_ID = '" + Security.USER_ID.ToString() + "'" + ControlChars.CrLf;
using (IDbCommand cmd = con.CreateCommand())
{
cmd.CommandText = sSQL;
using (DbDataAdapter da = dbf.CreateDataAdapter())
{
((IDbDataAdapter)da).SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
da.Fill(dt);
vwMain2 = dt.DefaultView;
GridView2.DataSource = vwMain2;
GridView2.DataBind();
}
}
}
}
}
catch (Exception ex)
{
SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
//lblError.Text = ex.Message;
}
}
我想遍历它并以以下格式创建一个 HTML 表:
<table>
<tbody>
<tr>
<th>Column Header</th>
</tr>
<tr>
<td>Column Data</td>
</tr>
</tbody>
</table>
做这个的最好方式是什么?我想在生成 HTML 后返回它。
谢谢你。