Programmatically changing CssStyle on Panels depending on DB values

M

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)
 
J

JDP@Work

Sorry that this is VB....

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....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top