Home All Groups Group Topic Archive Search About

Programmatically changing CssStyle on Panels depending on DB values

Author
17 Jun 2005 11:42 AM
mattsthompson
I am trying to change the look of a panel but only if that panel's ID
is returned by a database lookup.

I've tried using FindControl but this returns Controls and not
WebControls and I'm having difficulty converting items.

I'm coding in C#

I was hoping to do something along the lines of:

-- quote --
Control hControl = Page.FindControl(dr.GetString(4));

hControl.CssStyle = "MenuItemSelected";
-- end quote --

But the last line doesn't quite work ;o)

Author
22 Jun 2005 4:00 PM
JDP@Work
Sorry that this is VB....

<mattsthomp***@gmail.com> wrote in message
Show quoteHide quote
news:1119008553.651307.114810@o13g2000cwo.googlegroups.com...

> I am trying to change the look of a panel but only if that panel's ID
> is returned by a database lookup.
>
> I've tried using FindControl but this returns Controls and not
> WebControls and I'm having difficulty converting items.
>
> I'm coding in C#
>
> I was hoping to do something along the lines of:
>
> -- quote --
> Control hControl = Page.FindControl(dr.GetString(4));
>
> hControl.CssStyle = "MenuItemSelected";
> -- end quote --
>
> But the last line doesn't quite work ;o)
>

Sorry this is in VB

Call this on Fill() and/or whenever an event occurs, like a drop down is
selected or whatever....

.....snipit follows

Public Shared Sub SetupDynamicFields(ByVal formName As String, ByVal criteria As
String, ByVal page As Object)

Dim dr As SqlClient.SqlDataReader =
SqlHelper.ExecuteReader(Common.ConnectionString, "usp_GetControl_Info",
formName, criteria)

        Do While dr.Read

'.... make vars, get & do stuff

            Dim lbl As Label = page.FindControl(lblName)
            Dim rfv As RequiredFieldValidator = page.FindControl(rfvName)
            Dim tr As HtmlControls.HtmlTableRow = page.FindControl(trName)

            If Not lbl Is Nothing Then
                If dr.Item("Required") Then
                    lbl.CssClass = "StdFormLabelRequired"
                Else
                    lbl.CssClass = "StdFormLabel"
                End If
            End If

'.... setup Required as Enabled to enable any on page validators, a form field
can be visible but not enabled, (read only) or a label.
'..... setup Visiblity
'.... setup entire tr visibility, easy way to dispay or hide form fields on
certain criteria, rather than having an empty tr or a hanging label.

.....snipit end

HTH

JeffP....