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

x
?
Solved

Gridview/Formview - ASP.Net Page Lifecycle

Posted on 2006-11-01
3
Medium Priority
?
1,225 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 18

Expert Comment

by:Elvio Lujan
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 18

Accepted Solution

by:
Elvio Lujan earned 1500 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

916 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