Thanks for the advice curt but this still does not help me. If i try to set
the value for my linkbutton in Item_DataBound or Item_Created I get a object
not set to an instance of an object. Here is my code... The linkbutton
resides in a template column. What is wierd is the ButtonColumn that I
created that has an edit linkbutton alternates color on the grid. Why are
the TemplateColumn and ButtonColumn objects acting differently.
Public Class UpdateITemplateCol
Implements ITemplate
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control)
Implements System.Web.UI.ITemplate.InstantiateIn
Dim btn As New LinkButton
btn.Text = "Update"
btn.ID = "Update"
btn.CommandName = "Update"
btn.CausesValidation = True
container.Controls.Add(btn)
End Sub
End Class
Public Class BaseTemplate
Inherits System.Web.UI.Page
'''Item Databound DG Event''''
Private Sub dgBedInfo_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgBedInfo.ItemDataBound
Dim LinkBtn As LinkButton = CType(e.Item.FindControl("Update"),
LinkButton)
LinkBtn.ForeColor = GetUpdateLinkColor()
End Sub
'''Item Created DG Event"""
Private Sub dgBedInfo_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgBedInfo.ItemCreated
Dim LinkBtn As LinkButton = CType(e.Item.FindControl("Update"),
LinkButton)
LinkBtn.ForeColor = GetUpdateLinkColor()
End Sub
'''Alternating Color Sub'''
Private Function GetUpdateLinkColor() As System.Drawing.Color
'AlternatingColor is a session variable accessed through public property
If (AlternatingColor = "Blue") Then
AlternatingColor = "White"
Return System.Drawing.Color.Blue
Else
AlternatingColor = "Blue"
Return System.Drawing.Color.White
End If
End Function
End Class
"Curt_C [MVP]" wrote:
that's fine...
use the .Forecolor = GetColor(); as a function in the Item_DataBound (or
similar event) (perhaps Item_Created)
--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
"Max Weebler" wrote:
That might work if I was defining my controls in the aspx. file but I have a
base template page class. I am defining all my controls in the code behind.
"Curt_C [MVP]" wrote:
Ahh....
The Styles/Css are determining it's coloring. You may want to start with
adding a cssClass to that item, but in an alternating way. Perhaps use a <%=
%> to hold the cssClass where the value is a function that retrieves an
alternating value
myColor = blue
Sub GetColor() as String
if(myColor=blue) then
myColor=white
else
myColor=blue
end if
return myColor
End Sub
....untested but it should be enough to get you started...
--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
"Max Weebler" wrote:
> No I am trying to alternate the forecolor.... the LinkButtons TextColor. The
> BackColor is alternating which leads me to believe that its not changing the
> forecolor because it is a link and something is overriding the
> alternatingitemstyle for the datagrid. Right now the linkbutton's text is
> blue in every row. I need it to be blue/white/blue etc.
>
> "Curt_C [MVP]" wrote:
>
> > Just to clarify before I answer, you want to make a LinkButton column in a
> > DataGrid to alternate BackColor?
> >
> > If so, you may have to put a function in for the BackColor value.... a
> > simple if then else routine to alternate the color value, placing it in there.
> >
> > --
> > Curt Christianson
> > site: http://www.darkfalz.com
> > blog: http://blog.darkfalz.com
> >
> >
> >
> > "Max Weebler" wrote:
> >
> > > Hi,
> > > I have a datagrid built that has an alternating item style that sets the
> > > backcolor and ForeColor of its rows. I have 4 template columns. One of them
> > > has a LinkButton embedded in it to perform updates. All the styles that are
> > > set are being followed by all templated columns with the exception for the
> > > update column. The update column does set the BackColor appropriately but
> > > when setting its ForeColor the LinkButton's color is blue and remains blue
> > > for all rows. However in another column which is a ButtonColumn with a
> > > linkbutton in it as well for editing the colors are alternating fine. I
> > > cannot make the update column a ButtonColumn because it needs to be able to
> > > CauseValidation on the form and I could not find a property within the
> > > ButtonColumn to do that. I tried removing all styles from the style sheet
> > > pertaining to links but then my general windows environment settings started
> > > to take over. If anyone has any clues as to how I can alternate the
> > > forecolor I would greatly appreciated it.
> > > Thanks in advance,
> > > Max