Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

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?
0
runnerjp2005
Asked:
runnerjp2005
  • 12
  • 10
1 Solution
 
CodeCruiserCommented:
You have two lines for onmouseout. Is that intentional?
0
 
runnerjp2005Author Commented:
well i wont both background colour and forground colour to chnage back to original state on mouseout
0
 
CodeCruiserCommented:
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;")
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
runnerjp2005Author Commented:
that didnt work sadly .. same as before
0
 
CodeCruiserCommented:
>any idea why this code cancels each other out?
Can you describe that?
0
 
runnerjp2005Author Commented:
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
0
 
CodeCruiserCommented:
If you comment out backcolor, does it work for forecolor?
0
 
runnerjp2005Author Commented:
thats a no lol... so what would it be to chnage text colour to black?
0
 
runnerjp2005Author Commented:
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!
0
 
CodeCruiserCommented:
Is that code from one of the links? Because its different to what you showed earlier.
0
 
runnerjp2005Author Commented:
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';")
0
 
CodeCruiserCommented:
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';")

???
0
 
runnerjp2005Author Commented:
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?
0
 
runnerjp2005Author Commented:
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?
0
 
CodeCruiserCommented:
>but can i add all the cells together in 1 row?
You mean without borders around cell?
0
 
runnerjp2005Author Commented:
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';")
0
 
CodeCruiserCommented:
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
0
 
runnerjp2005Author Commented:
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 ??
0
 
runnerjp2005Author Commented:
infact the background only works for cell 1 also!
0
 
CodeCruiserCommented:
>this.originalstyle=this.style.backgroundColor

Should the above not be

this.originalstyle.backgroundcolor=this.style.backgroundColor
0
 
runnerjp2005Author Commented:
fixed it in the end
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 12
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now