Solved

Data-bound Label in FormView

Posted on 2006-11-03
2
1,033 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Explain Unit of Work pattern 2 48
What is MicroStrategy.NET? 2 47
Problem to page 4 27
Cannot upload files above 1mb IIS7 11 17
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

747 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

11 Experts available now in Live!

Get 1:1 Help Now