我有一个运行 5 次的 while 循环:
string qry = "Select * from tbl_Products order by ProductId";
SqlCommand cmd = new SqlCommand(qry, con);
con.Open();
sbProducts="<table><tr>";
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
sbProducts = sbProducts + "<td>";
sbProducts = sbProducts + "<Form>";
sbProducts = sbProducts + "123";
sbProducts = sbProducts + "</Form>";
sbProducts = sbProducts + "</td>";
}
sbProducts = sbProducts + "</table>";
CellTwo = sbProducts.ToString();
con.Close();
}
它的输出很好,但它没有包装第一次迭代 TD 没有用表单标签包装。这似乎非常不合逻辑。输出如下:
<table>
<tr>
<td>123</td>
<td><form>123</form></td>
<td><form>123</form></td>
<td><form>123</form></td>
<td><form>123</form></td>
</tr>
</table>