Home All Groups Group Topic Archive Search About

Reading / Modifying FormView Child Controls at Runtime

Author
3 Feb 2006 8:00 PM
Scott at Cedar Creek
Please excuse me for reposting, I am not sure I correctly articulated what I
am trying to do in my last post.

I have created a FormView with lots of label controls.  Depending on certain
other values obtained at runtime, I want to color-code a label inside the
form-view.  For example, if the text of Label1 = "Y" I want to set the
ForeColor property of Label7 (inside the FormView control) to Green.

I've tried:

FormView1.Label7.ForeColor = "green"
but I get an error.

I've tried:

FormView.FindControl("Label7").ForeColor = "green"
but I get an error.

I know what I want to do, and I think I've articulated it pretty clearly in
this post.  I'm just not aware of HOW to accomplish this.  Any help would be
greatly appreciated.

Scott (Can you tell I'm a newb?)

Author
4 Feb 2006 1:08 AM
Christopher Reed
You have to a Color enum when referencing color in this context.  So, try
this:

FormView1.Label7.ForeColor = Color.Green

--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

Show quoteHide quote
"Scott at Cedar Creek" <ScottatCedarCr***@discussions.microsoft.com> wrote
in message news:F417E203-C86B-4666-AF5B-FDC225380779@microsoft.com...
> Please excuse me for reposting, I am not sure I correctly articulated what
> I
> am trying to do in my last post.
>
> I have created a FormView with lots of label controls.  Depending on
> certain
> other values obtained at runtime, I want to color-code a label inside the
> form-view.  For example, if the text of Label1 = "Y" I want to set the
> ForeColor property of Label7 (inside the FormView control) to Green.
>
> I've tried:
>
> FormView1.Label7.ForeColor = "green"
> but I get an error.
>
> I've tried:
>
> FormView.FindControl("Label7").ForeColor = "green"
> but I get an error.
>
> I know what I want to do, and I think I've articulated it pretty clearly
> in
> this post.  I'm just not aware of HOW to accomplish this.  Any help would
> be
> greatly appreciated.
>
> Scott (Can you tell I'm a newb?)
Author
4 Feb 2006 12:36 PM
Phillip Williams
Hello Scott,

The FormView.Row represents the row in the FormView.

You can access your Label control using the FindControls like this:

Dim row As FormViewRow = FormView1.Row
       Dim myLabel as Label
       dim cntrl as Control = row.FindControl("Label7")
       If Not cntrl Is Nothing Then   'if you found the control
          'explicitly converting the found object to a Label Control
          myLabel = Ctype(cntrl, Label) 
          myLabel.cssClass = "GreenClassStyle"
      End If

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


Show quoteHide quote
"Scott at Cedar Creek" wrote:

> Please excuse me for reposting, I am not sure I correctly articulated what I
> am trying to do in my last post.
>
> I have created a FormView with lots of label controls.  Depending on certain
> other values obtained at runtime, I want to color-code a label inside the
> form-view.  For example, if the text of Label1 = "Y" I want to set the
> ForeColor property of Label7 (inside the FormView control) to Green.
>
> I've tried:
>
> FormView1.Label7.ForeColor = "green"
> but I get an error.
>
> I've tried:
>
> FormView.FindControl("Label7").ForeColor = "green"
> but I get an error.
>
> I know what I want to do, and I think I've articulated it pretty clearly in
> this post.  I'm just not aware of HOW to accomplish this.  Any help would be
> greatly appreciated.
>
> Scott (Can you tell I'm a newb?)