Solved

Data-bound Label in FormView

Posted on 2006-11-03
2
1,038 Views
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);
base.OnInit(e);
}

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


0
Comment
Question by:doolinn
2 Comments
 
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

Bob
0
 
LVL 16

Accepted Solution

by:
Edwin_C earned 500 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.

aspx:

            <asp:FormView ID="FormView1" runat="server" OnDataBound="FormView1_DataBound">
                <ItemTemplate>
                    <asp:Label ID="label1" runat="server" Text='<%# Eval("field1") %>'></asp:Label>
                </ItemTemplate>
            </asp:FormView>
            <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).

Edwin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now