|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Programmatically changing CssStyle on Panels depending on DB valuesI 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 that this is VB....
<mattsthomp***@gmail.com> wrote in message Show quoteHide quote news:1119008553.651307.114810@o13g2000cwo.googlegroups.com... Sorry this is in 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) > 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....
Webform Navigation
Can't set button to Visible? Is someone willing to help me with a simple VB example? databind - XmlNodeList to DropDownList Need reviews and advice on web and data control tools and vendors custom web controls and conversion to inline code DataGrid NOT Paging Reach UserControl from ASPX codebehind? Web Custom Control using a property displaying current form text boxes A program about get value from datagrid cell |
|||||||||||||||||||||||