putting data in a label without using gridview, repeater etc ..

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

Hi,

i was wondering whether it's possible to get some data from a table and to
put it directly in a label without using gridview, reapeater, detailsview
etc ...

Here what i tried (doen't work): (this query returns only one record)

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myconn %>"
SelectCommand="SELECT [n1] FROM [mytable]"></asp:SqlDataSource>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("n1")
%>'></asp:Label>
....

Thanks
Eric
 
Do you want to do it that way or in code? In code would of course be easy,
just set a Variable to the result of ExecuteScalar (your sql) and:
Label1.Text = Variable

Justin.
 
Hi thanks for replying.
I know how to do it in code, but what i want to know is: is it possible to
do that in the aspx file, without code?
Thanks

Justin Dutoit said:
Do you want to do it that way or in code? In code would of course be easy,
just set a Variable to the result of ExecuteScalar (your sql) and:
Label1.Text = Variable

Justin.

Eric said:
Hi,

i was wondering whether it's possible to get some data from a table and
to put it directly in a label without using gridview, reapeater,
detailsview etc ...

Here what i tried (doen't work): (this query returns only one record)

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myconn %>"
SelectCommand="SELECT [n1] FROM
[mytable]"></asp:SqlDataSource>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("n1")
%>'></asp:Label>
...

Thanks
Eric
 
Back
Top