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

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
 
J

Justin Dutoit

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.
 
E

Eric

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top