Member_2_5230414
asked on
vb.net code does not work with e.Row.Attributes.Add
e.Row.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#FFFFFF'")
e.Row.Attributes.Add("onmouseover", "this.originalstyle2=this.style.foreColor;this.style.foreColor='#00000'")
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalstyle;")
e.Row.Attributes.Add("onmouseout", "this.style.foreColor=this.originalstyle2;")
any idea why this code cancels each other out?
You have two lines for onmouseout. Is that intentional?
ASKER
well i wont both background colour and forground colour to chnage back to original state on mouseout
Try using
e.Row.Attributes.Add("onmo useover", "this.originalstyle=this.s tyle.backg roundColor ;this.styl e.backgrou ndColor='# FFFFFF;thi s.original style2=thi s.style.fo reColor;th is.style.f oreColor=' #00000;'")
e.Row.Attributes.Add("onmo useout", "this.style.backgroundColo r=this.ori ginalstyle ;this.styl e.foreColo r=this.ori ginalstyle 2;")
e.Row.Attributes.Add("onmo
e.Row.Attributes.Add("onmo
ASKER
that didnt work sadly .. same as before
>any idea why this code cancels each other out?
Can you describe that?
Can you describe that?
ASKER
basically if i just run the background oart it works but when i add the forcolour it won't work for either forecolor or background
If you comment out backcolor, does it work for forecolor?
ASKER
thats a no lol... so what would it be to chnage text colour to black?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok the error lies here:
If e.Row.DataItem("important" ) = 1 Then
e.Row.Attributes.Add("onmo useover", "this.style.backgroundColo r='Chocola te'; this.style.color='pink'; this.style.cursor='pointer ';")
e.Row.BackColor = System.Drawing.ColorTransl ator.FromH tml("#0044 66")
e.Row.Cells(1).ForeColor = Drawing.Color.White
e.Row.Cells(2).ForeColor = Drawing.Color.White
e.Row.Cells(4).ForeColor = Drawing.Color.White
e.Row.Cells(6).ForeColor = Drawing.Color.White
End If
it always sets the colour as white!
If e.Row.DataItem("important"
e.Row.Attributes.Add("onmo
e.Row.BackColor = System.Drawing.ColorTransl
e.Row.Cells(1).ForeColor = Drawing.Color.White
e.Row.Cells(2).ForeColor = Drawing.Color.White
e.Row.Cells(4).ForeColor = Drawing.Color.White
e.Row.Cells(6).ForeColor = Drawing.Color.White
End If
it always sets the colour as white!
Is that code from one of the links? Because its different to what you showed earlier.
ASKER
no i relised i set the color if the important = 1 to this
but this seems to override the text colour (gained from the links)
e.Row.Attributes.Add("onmo useover", "this.style.backgroundColo r='Chocola te'; this.style.color='pink'; this.style.cursor='pointer ';")
e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#004466")
e.Row.Cells(1).ForeColor = Drawing.Color.White
e.Row.Cells(2).ForeColor = Drawing.Color.White
e.Row.Cells(4).ForeColor = Drawing.Color.White
e.Row.Cells(6).ForeColor = Drawing.Color.White
but this seems to override the text colour (gained from the links)
e.Row.Attributes.Add("onmo
So
>e.Row.BackColor = System.Drawing.ColorTransl ator.FromH tml("#0044 66")
is overriding
>e.Row.Attributes.Add("onm ouseover", "this.style.backgroundColo r='Chocola te'; this.style.color='pink'; this.style.cursor='pointer ';")
???
>e.Row.BackColor = System.Drawing.ColorTransl
is overriding
>e.Row.Attributes.Add("onm
???
ASKER
no that one isnt but
e.Row.Cells(1).ForeColor = Drawing.Color.White
e.Row.Cells(2).ForeColor = Drawing.Color.White
e.Row.Cells(4).ForeColor = Drawing.Color.White
e.Row.Cells(6).ForeColor = Drawing.Color.White
is overriding
this.style.color='pink'
i think its because i have set the colour to the cells itself?
e.Row.Cells(1).ForeColor = Drawing.Color.White
e.Row.Cells(2).ForeColor = Drawing.Color.White
e.Row.Cells(4).ForeColor = Drawing.Color.White
e.Row.Cells(6).ForeColor = Drawing.Color.White
is overriding
this.style.color='pink'
i think its because i have set the colour to the cells itself?
ASKER
Ok i think i know what to do
e.Row.Cells(1).Attributes. Add("onmou seover", "this.originalstyle=this.s tyle.backg roundColor ;this.styl e.backgrou ndColor='# FFFFFF'; this.style.color='black';" )
e.Row.Cells(2).Attributes. Add("onmou seover", "this.originalstyle=this.s tyle.backg roundColor ;this.styl e.backgrou ndColor='# FFFFFF'; this.style.color='black';" )
e.Row.Cells(4).Attributes. Add("onmou seover", "this.originalstyle=this.s tyle.backg roundColor ;this.styl e.backgrou ndColor='# FFFFFF'; this.style.color='black';" )
e.Row.Cells(6).Attributes. Add("onmou seover", "this.originalstyle=this.s tyle.backg roundColor ;this.styl e.backgrou ndColor='# FFFFFF'; this.style.color='black';" )
but can i add all the cells together in 1 row?
e.Row.Cells(1).Attributes.
e.Row.Cells(2).Attributes.
e.Row.Cells(4).Attributes.
e.Row.Cells(6).Attributes.
but can i add all the cells together in 1 row?
>but can i add all the cells together in 1 row?
You mean without borders around cell?
You mean without borders around cell?
ASKER
sorry i mean instead of repeating the code with 1.2.4.6
is there away i can do it like
e.Row.Cells(1)(2)(4)(6).At tributes.A dd("onmous eover", "this.originalstyle=this.s tyle.backg roundColor ;this.styl e.backgrou ndColor='# FFFFFF'; this.style.color='black';" )
is there away i can do it like
e.Row.Cells(1)(2)(4)(6).At
No you can do that. You can use a loop though
For I as integer = 0 to e.Row.Cells.Count - 1
e.Row.Cells(I).Attributes. Add(...)
Next
For I as integer = 0 to e.Row.Cells.Count - 1
e.Row.Cells(I).Attributes.
Next
ASKER
ok just wanted to check i was not going the long way around it
I am using the above code but it only seems to work for cell 1.
the background colour changes for them all but only the this.style.color='black' works for cell 1 ??
e.Row.Cells(1).Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#FFFFFF'; this.style.color='black';")
e.Row.Cells(2).Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#FFFFFF'; this.style.color='black';")
e.Row.Cells(4).Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#FFFFFF'; this.style.color='black';")
e.Row.Cells(6).Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#FFFFFF'; this.style.color='black';")
I am using the above code but it only seems to work for cell 1.
the background colour changes for them all but only the this.style.color='black' works for cell 1 ??
ASKER
infact the background only works for cell 1 also!
>this.originalstyle=this.s tyle.backg roundColor
Should the above not be
this.originalstyle.backgro undcolor=t his.style. background Color
Should the above not be
this.originalstyle.backgro
ASKER
fixed it in the end