Print Datatable in a DIV using Bind or Eval

-1

Is it possible to print the data of a DataTable ( codebehind ) in a div ?

    

Print data from datatable to Label .

How to use bind or eval ? Or some other way?

    
asked by anonymous 10.03.2014 / 21:10

1 answer

0

Ideally you should use a Gridview, Repeater, or a Listview (the latter two seem to be best for what you want, since you can mount them inside a div as you want). This link explains how to use Repeater: link

Using Repeater:

Assuming your DataTable (dt) has the columns id, name, sex, dTNum. On your aspx page it would look something like this:

<div>
   <asp:Repeater ID="rptMeuRepeater" runat="server">
      <ItemTemplate>
         <%# DataBinder.Eval(Container.DataItem, "id")%><br />
         <%# DataBinder.Eval(Container.DataItem, "nome")%><br />
         <%# DataBinder.Eval(Container.DataItem, "sexo")%><br />
         <%# DataBinder.Eval(Container.DataItem, "dtNascimento")%>
      </ItemTemplate>
   </asp:Repeater>
</div>

And to popular this repeater, do in your codebehind:

rptMeuRepeater.DataSource = dt;
rptMeuRepeater.DataBind();

And doing as you requested:

You can scroll through the columns of a DataTable and fill in your label, give more work;

Foreach (DataRow r in dt.Rows){
  lblTexto.Text += r["id"] + "<br />";
  lblTexto.Text += r["nome"] + "<br />";
  lblTexto.Text += r["sexo"] + "<br />";
  lblTexto.Text += r["dtNascimento"] + "<br />";
}
    
11.03.2014 / 17:33