Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Getting value from child control of formview

Reply
Thread Tools

Getting value from child control of formview

 
 
timpera2501
Guest
Posts: n/a
 
      01-19-2006
Hello,

I'm a bit of a newb, so please forgive me if this is a stupid question.

I have a simple formview that contains only one control (a label control
called "COUNTLabel"). The formview is bound to an ObjectDataSournce that
returns one value named "COUNT" which is assigned to this label control.

In the code behind, I've been trying to programmatically set the "Visible"
property of the formview control based on the value in the "COUNTLabel" label
control that is within the formview.

In the DataBinding event for the formview I have the following code:

if (EmergencyTTs.Row.FindControl("COUNTLabel").Equals (0))
{
EmergencyTTs.Visible = false;
}
else
{
EmergencyTTs.Visible = true;
}

But the value for "EmergencyTTs.Row.FindControl("COUNTLabel")" is always
null. What am I doing wrong?

Is there a better/easier way to go about going this?

 
Reply With Quote
 
 
 
 
Phillip Williams
Guest
Posts: n/a
 
      01-19-2006
You could have done it declaratively like this:

<asp:Label Id="COUNTLabel" runat="server" Text='<%# Bind ("COUNTFieldName")
%>' Visible='<%# Eval("COUNTFieldName").ToString().Equals("0") %>' ></Label>

You could have still done it the way you tried except that the syntax should
be corrected to look like this:
Label lbl=(Label)FormView1.Row.FindControl("COUNTLabel") ;
//if control is found
if (lbl !=null) lbl.Visible = lbl.Text.Equals("0");

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"timpera2501" wrote:

> Hello,
>
> I'm a bit of a newb, so please forgive me if this is a stupid question.
>
> I have a simple formview that contains only one control (a label control
> called "COUNTLabel"). The formview is bound to an ObjectDataSournce that
> returns one value named "COUNT" which is assigned to this label control.
>
> In the code behind, I've been trying to programmatically set the "Visible"
> property of the formview control based on the value in the "COUNTLabel" label
> control that is within the formview.
>
> In the DataBinding event for the formview I have the following code:
>
> if (EmergencyTTs.Row.FindControl("COUNTLabel").Equals (0))
> {
> EmergencyTTs.Visible = false;
> }
> else
> {
> EmergencyTTs.Visible = true;
> }
>
> But the value for "EmergencyTTs.Row.FindControl("COUNTLabel")" is always
> null. What am I doing wrong?
>
> Is there a better/easier way to go about going this?
>

 
Reply With Quote
 
 
 
 
Phillip Williams
Guest
Posts: n/a
 
      01-19-2006
The second alternative below should be used during the FomView.DataBinding or
FromView.DataBound or any later event, but not during handling the page.load,
as I explained, because the Page.Load event fires before the FormView is
populated with the data.

"Phillip Williams" wrote:

> You could have done it declaratively like this:
>
> <asp:Label Id="COUNTLabel" runat="server" Text='<%# Bind ("COUNTFieldName")
> %>' Visible='<%# Eval("COUNTFieldName").ToString().Equals("0") %>' ></Label>
>
> You could have still done it the way you tried except that the syntax should
> be corrected to look like this:
> Label lbl=(Label)FormView1.Row.FindControl("COUNTLabel") ;
> //if control is found
> if (lbl !=null) lbl.Visible = lbl.Text.Equals("0");
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "timpera2501" wrote:
>
> > Hello,
> >
> > I'm a bit of a newb, so please forgive me if this is a stupid question.
> >
> > I have a simple formview that contains only one control (a label control
> > called "COUNTLabel"). The formview is bound to an ObjectDataSournce that
> > returns one value named "COUNT" which is assigned to this label control.
> >
> > In the code behind, I've been trying to programmatically set the "Visible"
> > property of the formview control based on the value in the "COUNTLabel" label
> > control that is within the formview.
> >
> > In the DataBinding event for the formview I have the following code:
> >
> > if (EmergencyTTs.Row.FindControl("COUNTLabel").Equals (0))
> > {
> > EmergencyTTs.Visible = false;
> > }
> > else
> > {
> > EmergencyTTs.Visible = true;
> > }
> >
> > But the value for "EmergencyTTs.Row.FindControl("COUNTLabel")" is always
> > null. What am I doing wrong?
> >
> > Is there a better/easier way to go about going this?
> >

 
Reply With Quote
 
timpera2501
Guest
Posts: n/a
 
      01-19-2006
Phillip,

Thank you very much for taking the time to respond. =)

I made a method for the Formview Databinding and inserted the following code:

******************
protected void EmergencyTTs_DataBinding(object sender, EventArgs e)
{
Label lbl = (Label)EmergencyTTs.FindControl("COUNTLabel");
//if control is found
if (lbl != null) EmergencyTTs.Visible = lbl.Text.Equals("0");
}
******************

However, it still does not hide the formview when the value of the label is
0. Ideas?


"Phillip Williams" wrote:

> The second alternative below should be used during the FomView.DataBinding or
> FromView.DataBound or any later event, but not during handling the page.load,
> as I explained, because the Page.Load event fires before the FormView is
> populated with the data.
>
> "Phillip Williams" wrote:
>
> > You could have done it declaratively like this:
> >
> > <asp:Label Id="COUNTLabel" runat="server" Text='<%# Bind ("COUNTFieldName")
> > %>' Visible='<%# Eval("COUNTFieldName").ToString().Equals("0") %>' ></Label>
> >
> > You could have still done it the way you tried except that the syntax should
> > be corrected to look like this:
> > Label lbl=(Label)FormView1.Row.FindControl("COUNTLabel") ;
> > //if control is found
> > if (lbl !=null) lbl.Visible = lbl.Text.Equals("0");
> >
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "timpera2501" wrote:
> >
> > > Hello,
> > >
> > > I'm a bit of a newb, so please forgive me if this is a stupid question.
> > >
> > > I have a simple formview that contains only one control (a label control
> > > called "COUNTLabel"). The formview is bound to an ObjectDataSournce that
> > > returns one value named "COUNT" which is assigned to this label control.
> > >
> > > In the code behind, I've been trying to programmatically set the "Visible"
> > > property of the formview control based on the value in the "COUNTLabel" label
> > > control that is within the formview.
> > >
> > > In the DataBinding event for the formview I have the following code:
> > >
> > > if (EmergencyTTs.Row.FindControl("COUNTLabel").Equals (0))
> > > {
> > > EmergencyTTs.Visible = false;
> > > }
> > > else
> > > {
> > > EmergencyTTs.Visible = true;
> > > }
> > >
> > > But the value for "EmergencyTTs.Row.FindControl("COUNTLabel")" is always
> > > null. What am I doing wrong?
> > >
> > > Is there a better/easier way to go about going this?
> > >

 
Reply With Quote
 
Phillip Williams
Guest
Posts: n/a
 
      01-19-2006
Have you tried the declarative approach? (I tried it on my desktop and the
syntax works find)

Regarding the FormView.DataBinding approach you can set up break points on
the code and step through it to verify that the method is called, then look
at the values of the lbl.Text (maybe it is padded with spaces and therefore
you need to adjust the criteria for the if condition)
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"timpera2501" wrote:

> Phillip,
>
> Thank you very much for taking the time to respond. =)
>
> I made a method for the Formview Databinding and inserted the following code:
>
> ******************
> protected void EmergencyTTs_DataBinding(object sender, EventArgs e)
> {
> Label lbl = (Label)EmergencyTTs.FindControl("COUNTLabel");
> //if control is found
> if (lbl != null) EmergencyTTs.Visible = lbl.Text.Equals("0");
> }
> ******************
>
> However, it still does not hide the formview when the value of the label is
> 0. Ideas?
>
>
> "Phillip Williams" wrote:
>
> > The second alternative below should be used during the FomView.DataBinding or
> > FromView.DataBound or any later event, but not during handling the page.load,
> > as I explained, because the Page.Load event fires before the FormView is
> > populated with the data.
> >
> > "Phillip Williams" wrote:
> >
> > > You could have done it declaratively like this:
> > >
> > > <asp:Label Id="COUNTLabel" runat="server" Text='<%# Bind ("COUNTFieldName")
> > > %>' Visible='<%# Eval("COUNTFieldName").ToString().Equals("0") %>' ></Label>
> > >
> > > You could have still done it the way you tried except that the syntax should
> > > be corrected to look like this:
> > > Label lbl=(Label)FormView1.Row.FindControl("COUNTLabel") ;
> > > //if control is found
> > > if (lbl !=null) lbl.Visible = lbl.Text.Equals("0");
> > >
> > > --
> > > HTH,
> > > Phillip Williams
> > > http://www.societopia.net
> > > http://www.webswapp.com
> > >
> > >
> > > "timpera2501" wrote:
> > >
> > > > Hello,
> > > >
> > > > I'm a bit of a newb, so please forgive me if this is a stupid question.
> > > >
> > > > I have a simple formview that contains only one control (a label control
> > > > called "COUNTLabel"). The formview is bound to an ObjectDataSournce that
> > > > returns one value named "COUNT" which is assigned to this label control.
> > > >
> > > > In the code behind, I've been trying to programmatically set the "Visible"
> > > > property of the formview control based on the value in the "COUNTLabel" label
> > > > control that is within the formview.
> > > >
> > > > In the DataBinding event for the formview I have the following code:
> > > >
> > > > if (EmergencyTTs.Row.FindControl("COUNTLabel").Equals (0))
> > > > {
> > > > EmergencyTTs.Visible = false;
> > > > }
> > > > else
> > > > {
> > > > EmergencyTTs.Visible = true;
> > > > }
> > > >
> > > > But the value for "EmergencyTTs.Row.FindControl("COUNTLabel")" is always
> > > > null. What am I doing wrong?
> > > >
> > > > Is there a better/easier way to go about going this?
> > > >

 
Reply With Quote
 
timpera2501
Guest
Posts: n/a
 
      01-20-2006
Ah ha!!

Figured it out. The code works fine in the method, just instead of:

if (lbl != null) EmergencyTTs.Visible = lbl.Text.Equals("0");

Needed this:

if (lbl != null) EmergencyTTs.Visible = !(lbl.Text.Equals("0"));

=) Thank you sooo much for your help Phillip. Now I can get on with my life!

-Amanda


"Phillip Williams" wrote:

> Have you tried the declarative approach? (I tried it on my desktop and the
> syntax works find)
>
> Regarding the FormView.DataBinding approach you can set up break points on
> the code and step through it to verify that the method is called, then look
> at the values of the lbl.Text (maybe it is padded with spaces and therefore
> you need to adjust the criteria for the if condition)
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "timpera2501" wrote:
>
> > Phillip,
> >
> > Thank you very much for taking the time to respond. =)
> >
> > I made a method for the Formview Databinding and inserted the following code:
> >
> > ******************
> > protected void EmergencyTTs_DataBinding(object sender, EventArgs e)
> > {
> > Label lbl = (Label)EmergencyTTs.FindControl("COUNTLabel");
> > //if control is found
> > if (lbl != null) EmergencyTTs.Visible = lbl.Text.Equals("0");
> > }
> > ******************
> >
> > However, it still does not hide the formview when the value of the label is
> > 0. Ideas?
> >
> >
> > "Phillip Williams" wrote:
> >
> > > The second alternative below should be used during the FomView.DataBinding or
> > > FromView.DataBound or any later event, but not during handling the page.load,
> > > as I explained, because the Page.Load event fires before the FormView is
> > > populated with the data.
> > >
> > > "Phillip Williams" wrote:
> > >
> > > > You could have done it declaratively like this:
> > > >
> > > > <asp:Label Id="COUNTLabel" runat="server" Text='<%# Bind ("COUNTFieldName")
> > > > %>' Visible='<%# Eval("COUNTFieldName").ToString().Equals("0") %>' ></Label>
> > > >
> > > > You could have still done it the way you tried except that the syntax should
> > > > be corrected to look like this:
> > > > Label lbl=(Label)FormView1.Row.FindControl("COUNTLabel") ;
> > > > //if control is found
> > > > if (lbl !=null) lbl.Visible = lbl.Text.Equals("0");
> > > >
> > > > --
> > > > HTH,
> > > > Phillip Williams
> > > > http://www.societopia.net
> > > > http://www.webswapp.com
> > > >
> > > >
> > > > "timpera2501" wrote:
> > > >
> > > > > Hello,
> > > > >
> > > > > I'm a bit of a newb, so please forgive me if this is a stupid question.
> > > > >
> > > > > I have a simple formview that contains only one control (a label control
> > > > > called "COUNTLabel"). The formview is bound to an ObjectDataSournce that
> > > > > returns one value named "COUNT" which is assigned to this label control.
> > > > >
> > > > > In the code behind, I've been trying to programmatically set the "Visible"
> > > > > property of the formview control based on the value in the "COUNTLabel" label
> > > > > control that is within the formview.
> > > > >
> > > > > In the DataBinding event for the formview I have the following code:
> > > > >
> > > > > if (EmergencyTTs.Row.FindControl("COUNTLabel").Equals (0))
> > > > > {
> > > > > EmergencyTTs.Visible = false;
> > > > > }
> > > > > else
> > > > > {
> > > > > EmergencyTTs.Visible = true;
> > > > > }
> > > > >
> > > > > But the value for "EmergencyTTs.Row.FindControl("COUNTLabel")" is always
> > > > > null. What am I doing wrong?
> > > > >
> > > > > Is there a better/easier way to go about going this?
> > > > >

 
Reply With Quote
 
Phillip Williams
Guest
Posts: n/a
 
      01-20-2006
My pleasure.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"timpera2501" wrote:

> Ah ha!!
>
> Figured it out. The code works fine in the method, just instead of:
>
> if (lbl != null) EmergencyTTs.Visible = lbl.Text.Equals("0");
>
> Needed this:
>
> if (lbl != null) EmergencyTTs.Visible = !(lbl.Text.Equals("0"));
>
> =) Thank you sooo much for your help Phillip. Now I can get on with my life!
>
> -Amanda
>
>
> "Phillip Williams" wrote:
>
> > Have you tried the declarative approach? (I tried it on my desktop and the
> > syntax works find)
> >
> > Regarding the FormView.DataBinding approach you can set up break points on
> > the code and step through it to verify that the method is called, then look
> > at the values of the lbl.Text (maybe it is padded with spaces and therefore
> > you need to adjust the criteria for the if condition)
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "timpera2501" wrote:
> >
> > > Phillip,
> > >
> > > Thank you very much for taking the time to respond. =)
> > >
> > > I made a method for the Formview Databinding and inserted the following code:
> > >
> > > ******************
> > > protected void EmergencyTTs_DataBinding(object sender, EventArgs e)
> > > {
> > > Label lbl = (Label)EmergencyTTs.FindControl("COUNTLabel");
> > > //if control is found
> > > if (lbl != null) EmergencyTTs.Visible = lbl.Text.Equals("0");
> > > }
> > > ******************
> > >
> > > However, it still does not hide the formview when the value of the label is
> > > 0. Ideas?
> > >
> > >
> > > "Phillip Williams" wrote:
> > >
> > > > The second alternative below should be used during the FomView.DataBinding or
> > > > FromView.DataBound or any later event, but not during handling the page.load,
> > > > as I explained, because the Page.Load event fires before the FormView is
> > > > populated with the data.
> > > >
> > > > "Phillip Williams" wrote:
> > > >
> > > > > You could have done it declaratively like this:
> > > > >
> > > > > <asp:Label Id="COUNTLabel" runat="server" Text='<%# Bind ("COUNTFieldName")
> > > > > %>' Visible='<%# Eval("COUNTFieldName").ToString().Equals("0") %>' ></Label>
> > > > >
> > > > > You could have still done it the way you tried except that the syntax should
> > > > > be corrected to look like this:
> > > > > Label lbl=(Label)FormView1.Row.FindControl("COUNTLabel") ;
> > > > > //if control is found
> > > > > if (lbl !=null) lbl.Visible = lbl.Text.Equals("0");
> > > > >
> > > > > --
> > > > > HTH,
> > > > > Phillip Williams
> > > > > http://www.societopia.net
> > > > > http://www.webswapp.com
> > > > >
> > > > >
> > > > > "timpera2501" wrote:
> > > > >
> > > > > > Hello,
> > > > > >
> > > > > > I'm a bit of a newb, so please forgive me if this is a stupid question.
> > > > > >
> > > > > > I have a simple formview that contains only one control (a label control
> > > > > > called "COUNTLabel"). The formview is bound to an ObjectDataSournce that
> > > > > > returns one value named "COUNT" which is assigned to this label control.
> > > > > >
> > > > > > In the code behind, I've been trying to programmatically set the "Visible"
> > > > > > property of the formview control based on the value in the "COUNTLabel" label
> > > > > > control that is within the formview.
> > > > > >
> > > > > > In the DataBinding event for the formview I have the following code:
> > > > > >
> > > > > > if (EmergencyTTs.Row.FindControl("COUNTLabel").Equals (0))
> > > > > > {
> > > > > > EmergencyTTs.Visible = false;
> > > > > > }
> > > > > > else
> > > > > > {
> > > > > > EmergencyTTs.Visible = true;
> > > > > > }
> > > > > >
> > > > > > But the value for "EmergencyTTs.Row.FindControl("COUNTLabel")" is always
> > > > > > null. What am I doing wrong?
> > > > > >
> > > > > > Is there a better/easier way to go about going this?
> > > > > >

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
formview child controls .. added a table and broke control loop?? jobs ASP .Net Datagrid Control 0 07-21-2007 11:48 PM
Formview child control data retrieval Geek ASP .Net Web Controls 3 07-25-2006 06:30 AM
restrict the value of one child based on value from another child leon XML 0 09-27-2005 03:32 PM
Pass from parent to child, then update parent with child value... Noel Dolan Javascript 0 07-18-2004 05:52 PM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM



Advertisments