Solved

Gridview/Formview - ASP.Net Page Lifecycle

Posted on 2006-11-01
3
1,188 Views
Last Modified: 2011-08-18

I have a page with a label (label1) in a formview( FormView1) and a label (label2) in a gridview(MyGridView).

The gridview label gets its value from the formview ( see code below) on the page_load event.

everything works fine on page_load except  the gridview label shows the previous page's value. How do I ensure the formview is updated first and the gridview then reads the updated formview label?

Thanks!

protected void Page_Load(object sender, EventArgs e)
{
FormViewRow row = FormView1.Row
Label formlbl = (Label)row.FindControl("label1")
GridViewRow grdrow = MyGridView.HeaderRow;
Label grdlbl = (Label)grdrow.FindControl("label2")

grdlbl.text = formlbl.text
}



0
Comment
Question by:doolinn
  • 2
3 Comments
 
LVL 17

Expert Comment

by:lem2802
ID: 17849225
try...

protected void Page_Load(object sender, EventArgs e)
{
FormViewRow row = FormView1.Row
Label formlbl = (Label)row.FindControl("label1")
GridViewRow grdrow = MyGridView.HeaderRow;
(Label)grdrow.FindControl("label2").Text = formlbl.text;
}
0
 

Author Comment

by:doolinn
ID: 17850169
I'm afraid your suggested change returns the error 'System.Web.UI.Control' does not contain a definition for 'Text' on the changed line of code ...any more  thoughts on how I can get around this? Thanks!
0
 
LVL 17

Accepted Solution

by:
lem2802 earned 500 total points
ID: 17850217
protected void Page_Load(object sender, EventArgs e)
{
FormViewRow row = FormView1.Row
Label formlbl = (Label)row.FindControl("label1")
GridViewRow grdrow = MyGridView.HeaderRow;
((Label)grdrow.FindControl("label2")).Text = formlbl.text;
}
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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 …
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 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

18 Experts available now in Live!

Get 1:1 Help Now