C# 在我的表格中,ASPX页面的第一行为空,最后一行缺失
我尝试使用调试模式检查数据及其包含的所有行,但当我尝试显示时,第一行为空,最后一行缺失 以下是该表的视图:C# 在我的表格中,ASPX页面的第一行为空,最后一行缺失,c#,asp.net,css-tables,C#,Asp.net,Css Tables,我尝试使用调试模式检查数据及其包含的所有行,但当我尝试显示时,第一行为空,最后一行缺失 以下是该表的视图: 你能用Foreach试试吗 <% foreach (DataRow dr in ds.Tables[0].Rows)%> <%{ %> <tr> <td> <asp:label id="L1" runat="server" text=""></asp:label>
你能用Foreach试试吗
<% foreach (DataRow dr in ds.Tables[0].Rows)%>
<%{ %>
<tr>
<td>
<asp:label id="L1" runat="server" text=""></asp:label>
<% L1.Text = dr["com_id"].ToString(); %></td>
<td>
<asp:label id="L2" runat="server" text=""></asp:label>
<% L2.Text = dr["company_name"].ToString(); %></td>
<td>
<asp:label id="L3" runat="server" text=""></asp:label>
<% L3.Text = dr["openbal"].ToString(); %></td>
<td>
<asp:label id="L4" runat="server" text=""></asp:label>
<% L4.Text = dr["city"].ToString(); %></td>
</tr>
<% }
我是这样做的,效果很好。但仍不明白为什么上述方法不起作用
C#
if(!object.Equals(ds.Tables[0],null))
{
如果(ds.Tables[0].Rows.Count>0)
{
对于(int i=0;i
.aspx
身份证件
公司
期初余额
城市
相同的结果,兄弟。
public static Cmd(string q)
{
con.Open();
SqlDataAdapter command = new SqlDataAdapter(q, ConSetting.con);
command.SelectCommand.CommandType = CommandType.StoredProcedure;
con.Close();
DataSet ds = new DataSet();
command.Fill(ds);
}
<% foreach (DataRow dr in ds.Tables[0].Rows)%>
<%{ %>
<tr>
<td>
<asp:label id="L1" runat="server" text=""></asp:label>
<% L1.Text = dr["com_id"].ToString(); %></td>
<td>
<asp:label id="L2" runat="server" text=""></asp:label>
<% L2.Text = dr["company_name"].ToString(); %></td>
<td>
<asp:label id="L3" runat="server" text=""></asp:label>
<% L3.Text = dr["openbal"].ToString(); %></td>
<td>
<asp:label id="L4" runat="server" text=""></asp:label>
<% L4.Text = dr["city"].ToString(); %></td>
</tr>
<% }
if (!object.Equals(ds.Tables[0], null))
{
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
htmlTable.Append("<tr>");
htmlTable.Append("<td>" + ds.Tables[0].Rows[i]["com_id"] + "</td>");
htmlTable.Append("<td>" + ds.Tables[0].Rows[i]["company_name"] + "</td>");
htmlTable.Append("<td>" + ds.Tables[0].Rows[i]["openbal"] + "</td>");
htmlTable.Append("<td>" + ds.Tables[0].Rows[i]["city"] + "</td>");
htmlTable.Append("</tr>");
}
tabledata.Controls.Add(new Literal { Text = htmlTable.ToString() });
}
else
{
htmlTable.Append("<tr>");
htmlTable.Append("<td align='center' colspan='4'>There is no Record.</td>");
htmlTable.Append("</tr>");
}
}
<table class="table table-bordered table-striped table-hover ">
<thead style="text-align-last: center; background-color: black; color: white">
<th>Id</th>
<th>Company</th>
<th>Opening Balance</th>
<th>City</th>
</thead>
<tbody id="myTable" style="text-align: center;">
<asp:PlaceHolder ID="tabledata" runat="server"></asp:PlaceHolder>
</tbody>
</table>