Link to home
Start Free TrialLog in
Avatar of Member_2_5230414
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;")

Open in new window


any idea why this code cancels each other out?
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

You have two lines for onmouseout. Is that intentional?
Avatar of Member_2_5230414
Member_2_5230414

ASKER

well i wont both background colour and forground colour to chnage back to original state on mouseout
Try using

 e.Row.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#FFFFFF;this.originalstyle2=this.style.foreColor;this.style.foreColor='#00000;'")
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalstyle;this.style.foreColor=this.originalstyle2;")
that didnt work sadly .. same as before
>any idea why this code cancels each other out?
Can you describe that?
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?
thats a no lol... so what would it be to chnage text colour to black?
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok the error lies here:

   If e.Row.DataItem("important") = 1 Then
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='Chocolate'; 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


            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.
no i relised i set the color if the important = 1 to this

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

Open in new window



but this seems to override the text colour (gained from the links)

            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='Chocolate'; this.style.color='pink'; this.style.cursor='pointer';")
So
>e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#004466")

is overriding
>e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='Chocolate'; this.style.color='pink'; this.style.cursor='pointer';")

???
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?
Ok i think i know what to do

 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';")

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?
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).Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#FFFFFF'; this.style.color='black';")
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
ok just wanted to check i was not going the long way around it

 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';")

Open in new window


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 ??
infact the background only works for cell 1 also!
>this.originalstyle=this.style.backgroundColor

Should the above not be

this.originalstyle.backgroundcolor=this.style.backgroundColor
fixed it in the end