Data-bound Label in FormView

Posted on 2006-11-03
Medium Priority
Last Modified: 2008-02-01

I have a label in a formview(label1) bound to a datasource.

(ref:- This label's text updates everytime a dropdown control is changed).

How do I show the value of this label outside the formview in (i) a another label (label2) on the main page or (ii) in a label in another formview?

At the moment, for (i)  I have tried :-

protected override void OnInit (EventArgs e)
FormView1.ItemCreated += new EventHandler(FormView1_ItemCreated);

protected void FormView1_ItemCreated (Object sender, EventArgs e)
FormViewRow row = FormView1.Row;
Label lbl =((Label).row.FindControl("Label1");
Label2.Text= lbl.Text;

.............For some reason Label2 remains blank with this code...

Question by:doolinn
LVL 96

Expert Comment

by:Bob Learned
ID: 17866023
If you want to pass the value onto another page, you have some options--QueryString, Session, temporary cookie

LVL 16

Accepted Solution

Edwin_C earned 2000 total points
ID: 17866819
You cannot get the text from the label when ItemCreated because the label contains nothing at that time.  You should do it in the DataBound event.


            <asp:FormView ID="FormView1" runat="server" OnDataBound="FormView1_DataBound">
                    <asp:Label ID="label1" runat="server" Text='<%# Eval("field1") %>'></asp:Label>
            <br />
            <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>

Code behind:

    protected void FormView1_DataBound(object sender, EventArgs e)
        this.Label2.Text = ((Label)FormView1.FindControl("Label1")).Text;

Regrading the second part of your question, you can assign the text to a label inside another formview provided that the formview has been bound to a valid record (so that the label inside it is created).


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Watch the video to know how one can repair corrupt Exchange OST file effortlessly and convert OST emails to MS Outlook PST file format by using Kernel for OST to PST converter tool. It can convert OST to MSG, MBOX, EML to access them. It can migrate…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question