Yes, just do it the same way you would set any attribute dynamically. Here
are several methods I am working that you may be interested in that will
soon be on my website (they are written using VB.NET 2.0, but they could
easily be modified if you need to convert them to C#):
Public Class Rollovers
Public Shared Sub AddRolloverExpansionHeight(ByVal ctrl As
System.Web.UI.WebControls.WebControl, ByVal initialheight As String, ByVal
expandedheight As String)
If ctrl.Style.Value = Nothing Then
ctrl.Style.Value =
String.Format("display:block;overflow:hidden;height:{0};", initialheight)
Else
If Not ctrl.Style.Value.Contains("display:block") Then ctrl.Style.Value =
"display:block;" & ctrl.Style.Value
If Not ctrl.Style.Value.Contains("overflow:hidden") Then ctrl.Style.Value
= "overflow:hidden;" & ctrl.Style.Value
ctrl.Style.Value &= String.Format("height:{0};", initialheight)
End If
ctrl.Attributes.Add("onmouseover",
String.Format("this.style.height='{0}';", expandedheight))
ctrl.Attributes.Add("onmouseout",
String.Format("this.style.height='{0}';", initialheight))
End Sub
Public Shared Sub AddRolloverExpansionHeight(ByVal ctrl As
System.Web.UI.WebControls.WebControl, ByVal initialheight As String)
AddRolloverExpansionHeight(ctrl, initialheight, "auto")
End Sub
Public Shared Sub AddRolloverExpansionWidth(ByVal ctrl As
System.Web.UI.WebControls.WebControl, ByVal initialwidth As String, ByVal
expandedwidth As String)
If ctrl.Style.Value = Nothing Then
ctrl.Style.Value =
String.Format("display:block;overflow:hidden;width:{0};", initialwidth)
Else
If Not ctrl.Style.Value.Contains("display:block") Then ctrl.Style.Value =
"display:block;" & ctrl.Style.Value
If Not ctrl.Style.Value.Contains("overflow:hidden") Then ctrl.Style.Value
= "overflow:hidden;" & ctrl.Style.Value
ctrl.Style.Value &= String.Format("width:{0};", initialwidth)
End If
ctrl.Attributes.Add("onmouseover",
String.Format("this.style.width='{0}';", expandedwidth))
ctrl.Attributes.Add("onmouseout", String.Format("this.style.width='{0}';",
initialwidth))
End Sub
Public Shared Sub AddRolloverExpansionWidth(ByVal ctrl As
System.Web.UI.WebControls.WebControl, ByVal initialwidth As String)
AddRolloverExpansionWidth(ctrl, initialwidth, "auto")
End Sub
Public Shared Sub AddRolloverExpansion(ByVal ctrl As
System.Web.UI.WebControls.WebControl, ByVal initialheight As String, ByVal
initialwidth As String, ByVal expandedheight As String, ByVal expandedwidth
As String)
If ctrl.Style.Value = Nothing Then
ctrl.Style.Value =
String.Format("display:block;overflow:hidden;height:{0};width:{1};",
initialheight, initialwidth)
Else
If Not ctrl.Style.Value.Contains("display:block") Then ctrl.Style.Value =
"display:block;" & ctrl.Style.Value
If Not ctrl.Style.Value.Contains("overflow:hidden") Then ctrl.Style.Value
= "overflow:hidden;" & ctrl.Style.Value
ctrl.Style.Value &= String.Format("height:{0};width:{1};", initialheight,
initialwidth)
End If
ctrl.Attributes.Add("onmouseover",
String.Format("this.style.height='{0}';this.style.width='{1}';",
expandedheight, expandedwidth))
ctrl.Attributes.Add("onmouseout",
String.Format("this.style.height='{0}';this.style.width='{1}';",
initialheight, initialwidth))
End Sub
Public Shared Sub AddRolloverExpansion(ByVal ctrl As
System.Web.UI.WebControls.WebControl, ByVal initialheight As String, ByVal
initialwidth As String)
AddRolloverExpansion(ctrl, initialheight, initialwidth, "auto", "auto")
End Sub
End Class