Solved

Data-bound Label in FormView

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

839 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