Solved

Gridview/Formview - ASP.Net Page Lifecycle

Posted on 2006-11-01
3
1,197 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 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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.

821 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