Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Data-bound Label in FormView

Posted on 2006-11-03
2
Medium Priority
?
1,048 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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.

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

664 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