.net获取DataTable里面的值(asp.net遍历获取datatable的值)

时间:2022-02-01 10:47:57

方法一:
for (int i =0; i < dtb_xx.Rows.Count; i++ )
{
response.write dtb_xx.Rows[i]["szxxxx1"].ToString();
response.write dtb_xx.Rows[i]["szxxxx2"].ToString();
}

方法二:
if (dtb_xx.Rows.Count > 0)
              {
                  foreach (DataRow dr in dtb_xx.Rows)
                  {
                      response.write dr["szxx1"].ToString();
                      response.write dr["szxx2"].ToString();
                  }
              }

方法三:
绑定DataTable到Reapter。
if (dtb_xx.Rows.Count > 0)
        {
            rp_xx.DataSource = dtb_xx;
            rp_xx.DataBind();
        }
<asp:Repeater ID="rp_xx" runat="server">
       <ItemTemplate>
            <tr>
                  <td>
                      <div>
                            <ul class="ListHorizontally">
                                 <li>
                                      <div class="TCell1">
                                            <%#Eval("ID")%>
                                       </div>
                                  </li>
                                  <li>
                                       <div class="TCell2">
                                             <%#Eval("Name")%>
                                        </div>
                                  </li>
                            </ul>
                       </div>
                    </td>
                </tr>
            </ItemTemplate>
         </asp:Repeater>