我有一个链接,它会调用带有用c#编写的代码文件的asp。这将从ms sql db构建动态页面结果集查询。
运行查询的c#类是
public DataTable GetResultList(string StagingPKID)
{
DataTable rst = mwGeneric.RunSQL(
SafewayPlatform.LOGIX_DATABASE.XS,
@"select Staging_ExtCardID as 'Card/HH number', Status from dbo.CGD_CGLoader_GMStatus with (noLock) where Staging_PKID = "+StagingPKID+" order by LastUpdate desc"
);
return rst;
}
结果集将传递给类
之外的数据表DataTable dt = new DataTable();
dt = oCond.GetResultList(StagingPKID);
然后构建html表,循环数据集以填充行
//Building an HTML string.
StringBuilder html = new StringBuilder();
//Table start.
html.Append("<table>");
//Building the Header row.
html.Append("<tr>");
foreach (DataColumn column in dt.Columns)
{
html.Append("<th>");
html.Append(column.ColumnName);
html.Append("</th>");
}
html.Append("</tr>");
//Building the Data rows.
foreach (DataRow row in dt.Rows)
{
html.Append("<tr>");
foreach (DataColumn column in dt.Columns)
{
html.Append("<td>");
html.Append(row[column.ColumnName]);
html.Append("</td>");
}
html.Append("</tr>");
}
//Table end.
html.Append("</table>");
我将html放在占位符
上PlaceHolder1.Controls.Add(new Literal { Text = html.ToString() });
最后在asp上编写了html主体。
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<h2 style="border-radius:10px;background-color:#99ccff;padding:15px;text-align:center;">File Upload Report</h2>
</div>
</div>
<form id="form1" runat="server">
<asp:PlaceHolder ID = "PlaceHolder1" runat="server" />
</form>
</div>
</body>
如何限制在页面上显示最多100个结果并有链接并迭代显示下一个结果集?
我最初想过在查询中使用行号,如下所示;
select
"Card/HH number",
Status
from (
select
row_number() over (order by LastUpdate desc) as 'rownbr',
Staging_ExtCardID as 'Card/HH number',
Status
from dbo.CGD_CGLoader_GMStatus with (noLock)) As Table1
where Table1.rownbr between 1 and 100
但我不确定这是否是正确的方法,因为我必须在条件初步检查结果集是否大于100并且将数字之间的数字作为变量,以便用户可以来回导航结果集。