Accessing a Label control programmatically in codebehind for asp.net 2

P

Paul

I am using Visual Studio.net 2005 (and asp.net 2.0)
Let's say that in a Web Project, I have created a (Dataset?) called
SomeDataset.xsd.
On it I have a TableAdapter called SomeTableTableAdapter and a query called
GetSomeInfoQuery.

In an aspx page I used an ObjectDataSource, and chose as the business object
SomeDataSetTableAdapters.SomeTableTableAdapter, then the method
GetSomeInfoQuery.

On the aspx side of the page I have a have a FormView with various objects
(labels) displayed that use the Eval("SomeItem") syntax to render.

Everything works fine, displaying what is supposed to dispaly.

Question: How would I assign a label value programmatically in the
codebehind of the page?

I tried Label.text=Eval("Something1") copying it form the source of the aspx
page, but it (naturally) did not work.

In asp.net 1.1, there was a whole riggamarole that was necessary, writing
class files etc, then instantiating them in the page.aspx.vb... Is there an
easier way to do it in asp.net 2?

TIA,

Paul
 
G

Guest

The Eval("") uses a particular object that evaluates for tagged portions. To
bind to a label in codebehind, there is no eval. Instead, you have to bind
the particular object to the label. In the table adapter, you will have to
pull the field out of a DataRow from a DataTable returned by the table
adapter. I do not have sample code on this.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
A

Anthony Merante

Mr Beamer is right

But to add
You could also do something like this though:

on the aspx

<asp:Label runat='server" id="myLabel" text="<%# Eval("Col") %>" />

providing that the label is within a container that DataBind() was called
on.

Dunno if that is what you want though
 
P

Paul

Thanks.

In the codebehind, I am filling the label object using an
ObjectStreamReader, so I think I need to do the coding in the code-behind
page. I am also just plain curious about how to do it in asp.net 2. In
asp.net 1.* it was laborious, but very do-able.



Thanks again to you and to Mr. Beamer,

Paul
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top