Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Data-bound Label in FormView

Posted on 2006-11-03
2
Medium Priority
?
1,050 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

971 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