onmouse over in datagrid

Discussion in 'ASP .Net Datagrid Control' started by Jairo Nieto, Feb 18, 2004.

  1. Jairo Nieto

    Jairo Nieto Guest

    Hi i am currently developing a Datagrid that changes background color when
    the user rolls over his mouse on a row.

    Here's how I handle it:
    void dg_menu_ItemDataBound(object sender, DataGridItemEventArgs e)

    { if(e.Item.Cells[2].Text != null && e.Item.Cells[2].Text != " ")

    { e.Item.Cells[3].Attributes.Add("onmouseover",
    "this.style.backgroundColor='white'");

    e.Item.Cells[3].Attributes.Add("onmouseout",
    "this.style.backgroundColor='blue'");

    }

    }

    So far so good. My problem is that i need to asign the cell color to a css
    class. i have tried assigning the class directly, changing style for class,
    but nothing seems to work. How can i do it?

    Thx :)
    Jairo Nieto, Feb 18, 2004
    #1
    1. Advertising

  2. Your post went unanswered. Have you resolved this issue?

    --
    Regards,
    Alvin Bruney [ASP.NET MVP]
    Got tidbits? Get it here...
    http://tinyurl.com/3he3b
    "Jairo Nieto" <> wrote in message
    news:...
    > Hi i am currently developing a Datagrid that changes background color when
    > the user rolls over his mouse on a row.
    >
    > Here's how I handle it:
    > void dg_menu_ItemDataBound(object sender, DataGridItemEventArgs e)
    >
    > { if(e.Item.Cells[2].Text != null && e.Item.Cells[2].Text != "&nbsp;")
    >
    > { e.Item.Cells[3].Attributes.Add("onmouseover",
    > "this.style.backgroundColor='white'");
    >
    > e.Item.Cells[3].Attributes.Add("onmouseout",
    > "this.style.backgroundColor='blue'");
    >
    > }
    >
    > }
    >
    > So far so good. My problem is that i need to asign the cell color to a css
    > class. i have tried assigning the class directly, changing style for

    class,
    > but nothing seems to work. How can i do it?
    >
    > Thx :)
    >
    >
    Alvin Bruney [MVP], Mar 2, 2004
    #2
    1. Advertising

  3. Jairo Nieto

    Jairo Nieto Guest

    Nope, i havent been able to solve it :(

    "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    news:...
    > Your post went unanswered. Have you resolved this issue?
    >
    > --
    > Regards,
    > Alvin Bruney [ASP.NET MVP]
    > Got tidbits? Get it here...
    > http://tinyurl.com/3he3b
    > "Jairo Nieto" <> wrote in message
    > news:...
    > > Hi i am currently developing a Datagrid that changes background color

    when
    > > the user rolls over his mouse on a row.
    > >
    > > Here's how I handle it:
    > > void dg_menu_ItemDataBound(object sender, DataGridItemEventArgs e)
    > >
    > > { if(e.Item.Cells[2].Text != null && e.Item.Cells[2].Text !=

    "&nbsp;")
    > >
    > > { e.Item.Cells[3].Attributes.Add("onmouseover",
    > > "this.style.backgroundColor='white'");
    > >
    > > e.Item.Cells[3].Attributes.Add("onmouseout",
    > > "this.style.backgroundColor='blue'");
    > >
    > > }
    > >
    > > }
    > >
    > > So far so good. My problem is that i need to asign the cell color to a

    css
    > > class. i have tried assigning the class directly, changing style for

    > class,
    > > but nothing seems to work. How can i do it?
    > >
    > > Thx :)
    > >
    > >

    >
    >
    Jairo Nieto, Mar 2, 2004
    #3
  4. why do you need to assing to a css class? what are you trying to achieve?

    --
    Regards,
    Alvin Bruney [ASP.NET MVP]
    Got tidbits? Get it here...
    http://tinyurl.com/3he3b
    "Jairo Nieto" <> wrote in message
    news:...
    > Nope, i havent been able to solve it :(
    >
    > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    > news:...
    > > Your post went unanswered. Have you resolved this issue?
    > >
    > > --
    > > Regards,
    > > Alvin Bruney [ASP.NET MVP]
    > > Got tidbits? Get it here...
    > > http://tinyurl.com/3he3b
    > > "Jairo Nieto" <> wrote in message
    > > news:...
    > > > Hi i am currently developing a Datagrid that changes background color

    > when
    > > > the user rolls over his mouse on a row.
    > > >
    > > > Here's how I handle it:
    > > > void dg_menu_ItemDataBound(object sender, DataGridItemEventArgs e)
    > > >
    > > > { if(e.Item.Cells[2].Text != null && e.Item.Cells[2].Text !=

    > "&nbsp;")
    > > >
    > > > { e.Item.Cells[3].Attributes.Add("onmouseover",
    > > > "this.style.backgroundColor='white'");
    > > >
    > > > e.Item.Cells[3].Attributes.Add("onmouseout",
    > > > "this.style.backgroundColor='blue'");
    > > >
    > > > }
    > > >
    > > > }
    > > >
    > > > So far so good. My problem is that i need to asign the cell color to a

    > css
    > > > class. i have tried assigning the class directly, changing style for

    > > class,
    > > > but nothing seems to work. How can i do it?
    > > >
    > > > Thx :)
    > > >
    > > >

    > >
    > >

    >
    >
    Alvin Bruney [MVP], Mar 2, 2004
    #4
  5. sorry
    i meant to say why do you need to assign to a css class

    --
    Regards,
    Alvin Bruney [ASP.NET MVP]
    Got tidbits? Get it here...
    http://tinyurl.com/3he3b
    "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    news:...
    > why do you need to assing to a css class? what are you trying to achieve?
    >
    > --
    > Regards,
    > Alvin Bruney [ASP.NET MVP]
    > Got tidbits? Get it here...
    > http://tinyurl.com/3he3b
    > "Jairo Nieto" <> wrote in message
    > news:...
    > > Nope, i havent been able to solve it :(
    > >
    > > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    > > news:...
    > > > Your post went unanswered. Have you resolved this issue?
    > > >
    > > > --
    > > > Regards,
    > > > Alvin Bruney [ASP.NET MVP]
    > > > Got tidbits? Get it here...
    > > > http://tinyurl.com/3he3b
    > > > "Jairo Nieto" <> wrote in message
    > > > news:...
    > > > > Hi i am currently developing a Datagrid that changes background

    color
    > > when
    > > > > the user rolls over his mouse on a row.
    > > > >
    > > > > Here's how I handle it:
    > > > > void dg_menu_ItemDataBound(object sender, DataGridItemEventArgs e)
    > > > >
    > > > > { if(e.Item.Cells[2].Text != null && e.Item.Cells[2].Text !=

    > > "&nbsp;")
    > > > >
    > > > > { e.Item.Cells[3].Attributes.Add("onmouseover",
    > > > > "this.style.backgroundColor='white'");
    > > > >
    > > > > e.Item.Cells[3].Attributes.Add("onmouseout",
    > > > > "this.style.backgroundColor='blue'");
    > > > >
    > > > > }
    > > > >
    > > > > }
    > > > >
    > > > > So far so good. My problem is that i need to asign the cell color to

    a
    > > css
    > > > > class. i have tried assigning the class directly, changing style for
    > > > class,
    > > > > but nothing seems to work. How can i do it?
    > > > >
    > > > > Thx :)
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Alvin Bruney [MVP], Mar 3, 2004
    #5
  6. Jairo Nieto

    Jairo Nieto Guest

    I need a css class because the datagrid is part of a user control, that will
    be used over and over again in different proyects, that use different
    styles, and hence different colours, so i need the datagrid to be able to
    asume a css class on a mouse over, mouse out event (specially on the mouse
    out event so that it will assume the color it had before, given by the css
    class). So far, all the examples i have found assign static colors to the
    datagrid on mouseover/mouseout, but i need to be able to assign them
    dinamically.

    Thanks :)

    "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    news:%...
    > sorry
    > i meant to say why do you need to assign to a css class
    >
    > --
    > Regards,
    > Alvin Bruney [ASP.NET MVP]
    > Got tidbits? Get it here...
    > http://tinyurl.com/3he3b
    > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    > news:...
    > > why do you need to assing to a css class? what are you trying to

    achieve?
    > >
    > > --
    > > Regards,
    > > Alvin Bruney [ASP.NET MVP]
    > > Got tidbits? Get it here...
    > > http://tinyurl.com/3he3b
    > > "Jairo Nieto" <> wrote in message
    > > news:...
    > > > Nope, i havent been able to solve it :(
    > > >
    > > > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    > > > news:...
    > > > > Your post went unanswered. Have you resolved this issue?
    > > > >
    > > > > --
    > > > > Regards,
    > > > > Alvin Bruney [ASP.NET MVP]
    > > > > Got tidbits? Get it here...
    > > > > http://tinyurl.com/3he3b
    > > > > "Jairo Nieto" <> wrote in message
    > > > > news:...
    > > > > > Hi i am currently developing a Datagrid that changes background

    > color
    > > > when
    > > > > > the user rolls over his mouse on a row.
    > > > > >
    > > > > > Here's how I handle it:
    > > > > > void dg_menu_ItemDataBound(object sender, DataGridItemEventArgs e)
    > > > > >
    > > > > > { if(e.Item.Cells[2].Text != null && e.Item.Cells[2].Text !=
    > > > "&nbsp;")
    > > > > >
    > > > > > { e.Item.Cells[3].Attributes.Add("onmouseover",
    > > > > > "this.style.backgroundColor='white'");
    > > > > >
    > > > > > e.Item.Cells[3].Attributes.Add("onmouseout",
    > > > > > "this.style.backgroundColor='blue'");
    > > > > >
    > > > > > }
    > > > > >
    > > > > > }
    > > > > >
    > > > > > So far so good. My problem is that i need to asign the cell color

    to
    > a
    > > > css
    > > > > > class. i have tried assigning the class directly, changing style

    for
    > > > > class,
    > > > > > but nothing seems to work. How can i do it?
    > > > > >
    > > > > > Thx :)
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Jairo Nieto, Mar 3, 2004
    #6
  7. The datagrid exposes a CssClass read/write attribute. You can hook into this
    property like so
    DataGrid1.CssClass = "fillClass"

    --
    Regards,
    Alvin Bruney [ASP.NET MVP]
    Got tidbits? Get it here...
    http://tinyurl.com/3he3b
    "Jairo Nieto" <> wrote in message
    news:...
    > I need a css class because the datagrid is part of a user control, that

    will
    > be used over and over again in different proyects, that use different
    > styles, and hence different colours, so i need the datagrid to be able to
    > asume a css class on a mouse over, mouse out event (specially on the mouse
    > out event so that it will assume the color it had before, given by the css
    > class). So far, all the examples i have found assign static colors to the
    > datagrid on mouseover/mouseout, but i need to be able to assign them
    > dinamically.
    >
    > Thanks :)
    >
    > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    > news:%...
    > > sorry
    > > i meant to say why do you need to assign to a css class
    > >
    > > --
    > > Regards,
    > > Alvin Bruney [ASP.NET MVP]
    > > Got tidbits? Get it here...
    > > http://tinyurl.com/3he3b
    > > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    > > news:...
    > > > why do you need to assing to a css class? what are you trying to

    > achieve?
    > > >
    > > > --
    > > > Regards,
    > > > Alvin Bruney [ASP.NET MVP]
    > > > Got tidbits? Get it here...
    > > > http://tinyurl.com/3he3b
    > > > "Jairo Nieto" <> wrote in message
    > > > news:...
    > > > > Nope, i havent been able to solve it :(
    > > > >
    > > > > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in

    message
    > > > > news:...
    > > > > > Your post went unanswered. Have you resolved this issue?
    > > > > >
    > > > > > --
    > > > > > Regards,
    > > > > > Alvin Bruney [ASP.NET MVP]
    > > > > > Got tidbits? Get it here...
    > > > > > http://tinyurl.com/3he3b
    > > > > > "Jairo Nieto" <> wrote in message
    > > > > > news:...
    > > > > > > Hi i am currently developing a Datagrid that changes background

    > > color
    > > > > when
    > > > > > > the user rolls over his mouse on a row.
    > > > > > >
    > > > > > > Here's how I handle it:
    > > > > > > void dg_menu_ItemDataBound(object sender, DataGridItemEventArgs

    e)
    > > > > > >
    > > > > > > { if(e.Item.Cells[2].Text != null && e.Item.Cells[2].Text !=
    > > > > "&nbsp;")
    > > > > > >
    > > > > > > { e.Item.Cells[3].Attributes.Add("onmouseover",
    > > > > > > "this.style.backgroundColor='white'");
    > > > > > >
    > > > > > > e.Item.Cells[3].Attributes.Add("onmouseout",
    > > > > > > "this.style.backgroundColor='blue'");
    > > > > > >
    > > > > > > }
    > > > > > >
    > > > > > > }
    > > > > > >
    > > > > > > So far so good. My problem is that i need to asign the cell

    color
    > to
    > > a
    > > > > css
    > > > > > > class. i have tried assigning the class directly, changing style

    > for
    > > > > > class,
    > > > > > > but nothing seems to work. How can i do it?
    > > > > > >
    > > > > > > Thx :)
    > > > > > >
    > > > > > >
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Alvin Bruney [MVP], Mar 3, 2004
    #7
  8. Jairo Nieto

    Jairo Nieto Guest

    So the answer is to define the style for the whole datagrid and not just the
    row? then on the mouseover//mouseout i would change the whole datagrid
    class, with only the row color being different?

    "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    news:%...
    > The datagrid exposes a CssClass read/write attribute. You can hook into

    this
    > property like so
    > DataGrid1.CssClass = "fillClass"
    >
    > --
    > Regards,
    > Alvin Bruney [ASP.NET MVP]
    > Got tidbits? Get it here...
    > http://tinyurl.com/3he3b
    > "Jairo Nieto" <> wrote in message
    > news:...
    > > I need a css class because the datagrid is part of a user control, that

    > will
    > > be used over and over again in different proyects, that use different
    > > styles, and hence different colours, so i need the datagrid to be able

    to
    > > asume a css class on a mouse over, mouse out event (specially on the

    mouse
    > > out event so that it will assume the color it had before, given by the

    css
    > > class). So far, all the examples i have found assign static colors to

    the
    > > datagrid on mouseover/mouseout, but i need to be able to assign them
    > > dinamically.
    > >
    > > Thanks :)
    > >
    > > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    > > news:%...
    > > > sorry
    > > > i meant to say why do you need to assign to a css class
    > > >
    > > > --
    > > > Regards,
    > > > Alvin Bruney [ASP.NET MVP]
    > > > Got tidbits? Get it here...
    > > > http://tinyurl.com/3he3b
    > > > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    > > > news:...
    > > > > why do you need to assing to a css class? what are you trying to

    > > achieve?
    > > > >
    > > > > --
    > > > > Regards,
    > > > > Alvin Bruney [ASP.NET MVP]
    > > > > Got tidbits? Get it here...
    > > > > http://tinyurl.com/3he3b
    > > > > "Jairo Nieto" <> wrote in message
    > > > > news:...
    > > > > > Nope, i havent been able to solve it :(
    > > > > >
    > > > > > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in

    > message
    > > > > > news:...
    > > > > > > Your post went unanswered. Have you resolved this issue?
    > > > > > >
    > > > > > > --
    > > > > > > Regards,
    > > > > > > Alvin Bruney [ASP.NET MVP]
    > > > > > > Got tidbits? Get it here...
    > > > > > > http://tinyurl.com/3he3b
    > > > > > > "Jairo Nieto" <> wrote in message
    > > > > > > news:...
    > > > > > > > Hi i am currently developing a Datagrid that changes

    background
    > > > color
    > > > > > when
    > > > > > > > the user rolls over his mouse on a row.
    > > > > > > >
    > > > > > > > Here's how I handle it:
    > > > > > > > void dg_menu_ItemDataBound(object sender,

    DataGridItemEventArgs
    > e)
    > > > > > > >
    > > > > > > > { if(e.Item.Cells[2].Text != null && e.Item.Cells[2].Text

    !=
    > > > > > "&nbsp;")
    > > > > > > >
    > > > > > > > { e.Item.Cells[3].Attributes.Add("onmouseover",
    > > > > > > > "this.style.backgroundColor='white'");
    > > > > > > >
    > > > > > > > e.Item.Cells[3].Attributes.Add("onmouseout",
    > > > > > > > "this.style.backgroundColor='blue'");
    > > > > > > >
    > > > > > > > }
    > > > > > > >
    > > > > > > > }
    > > > > > > >
    > > > > > > > So far so good. My problem is that i need to asign the cell

    > color
    > > to
    > > > a
    > > > > > css
    > > > > > > > class. i have tried assigning the class directly, changing

    style
    > > for
    > > > > > > class,
    > > > > > > > but nothing seems to work. How can i do it?
    > > > > > > >
    > > > > > > > Thx :)
    > > > > > > >
    > > > > > > >
    > > > > > >
    > > > > > >
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Jairo Nieto, Mar 3, 2004
    #8
  9. no you can apply the css to lower levels such as to a particular cell.
    Consider this juicy snippet of code in the itemdatabound event handler

    e.Item.Cells[0].CssClass = "cssclass";

    The individual cells are as granular as you can get. Everything inbetween is
    fair game

    htt


    --
    Regards,
    Alvin Bruney [ASP.NET MVP]
    Got tidbits? Get it here...
    http://tinyurl.com/3he3b
    "Jairo Nieto" <> wrote in message
    news:ObA$...
    > So the answer is to define the style for the whole datagrid and not just

    the
    > row? then on the mouseover//mouseout i would change the whole datagrid
    > class, with only the row color being different?
    >
    > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    > news:%...
    > > The datagrid exposes a CssClass read/write attribute. You can hook into

    > this
    > > property like so
    > > DataGrid1.CssClass = "fillClass"
    > >
    > > --
    > > Regards,
    > > Alvin Bruney [ASP.NET MVP]
    > > Got tidbits? Get it here...
    > > http://tinyurl.com/3he3b
    > > "Jairo Nieto" <> wrote in message
    > > news:...
    > > > I need a css class because the datagrid is part of a user control,

    that
    > > will
    > > > be used over and over again in different proyects, that use different
    > > > styles, and hence different colours, so i need the datagrid to be able

    > to
    > > > asume a css class on a mouse over, mouse out event (specially on the

    > mouse
    > > > out event so that it will assume the color it had before, given by the

    > css
    > > > class). So far, all the examples i have found assign static colors to

    > the
    > > > datagrid on mouseover/mouseout, but i need to be able to assign them
    > > > dinamically.
    > > >
    > > > Thanks :)
    > > >
    > > > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    > > > news:%...
    > > > > sorry
    > > > > i meant to say why do you need to assign to a css class
    > > > >
    > > > > --
    > > > > Regards,
    > > > > Alvin Bruney [ASP.NET MVP]
    > > > > Got tidbits? Get it here...
    > > > > http://tinyurl.com/3he3b
    > > > > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in

    message
    > > > > news:...
    > > > > > why do you need to assing to a css class? what are you trying to
    > > > achieve?
    > > > > >
    > > > > > --
    > > > > > Regards,
    > > > > > Alvin Bruney [ASP.NET MVP]
    > > > > > Got tidbits? Get it here...
    > > > > > http://tinyurl.com/3he3b
    > > > > > "Jairo Nieto" <> wrote in message
    > > > > > news:...
    > > > > > > Nope, i havent been able to solve it :(
    > > > > > >
    > > > > > > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in

    > > message
    > > > > > > news:...
    > > > > > > > Your post went unanswered. Have you resolved this issue?
    > > > > > > >
    > > > > > > > --
    > > > > > > > Regards,
    > > > > > > > Alvin Bruney [ASP.NET MVP]
    > > > > > > > Got tidbits? Get it here...
    > > > > > > > http://tinyurl.com/3he3b
    > > > > > > > "Jairo Nieto" <> wrote in message
    > > > > > > > news:...
    > > > > > > > > Hi i am currently developing a Datagrid that changes

    > background
    > > > > color
    > > > > > > when
    > > > > > > > > the user rolls over his mouse on a row.
    > > > > > > > >
    > > > > > > > > Here's how I handle it:
    > > > > > > > > void dg_menu_ItemDataBound(object sender,

    > DataGridItemEventArgs
    > > e)
    > > > > > > > >
    > > > > > > > > { if(e.Item.Cells[2].Text != null &&

    e.Item.Cells[2].Text
    > !=
    > > > > > > "&nbsp;")
    > > > > > > > >
    > > > > > > > > { e.Item.Cells[3].Attributes.Add("onmouseover",
    > > > > > > > > "this.style.backgroundColor='white'");
    > > > > > > > >
    > > > > > > > > e.Item.Cells[3].Attributes.Add("onmouseout",
    > > > > > > > > "this.style.backgroundColor='blue'");
    > > > > > > > >
    > > > > > > > > }
    > > > > > > > >
    > > > > > > > > }
    > > > > > > > >
    > > > > > > > > So far so good. My problem is that i need to asign the cell

    > > color
    > > > to
    > > > > a
    > > > > > > css
    > > > > > > > > class. i have tried assigning the class directly, changing

    > style
    > > > for
    > > > > > > > class,
    > > > > > > > > but nothing seems to work. How can i do it?
    > > > > > > > >
    > > > > > > > > Thx :)
    > > > > > > > >
    > > > > > > > >
    > > > > > > >
    > > > > > > >
    > > > > > >
    > > > > > >
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Alvin Bruney [MVP], Mar 3, 2004
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cesar Zam
    Replies:
    0
    Views:
    333
    Cesar Zam
    Nov 6, 2003
  2. someone

    FTP over SSL vs FTP over SSH

    someone, Apr 24, 2004, in forum: Java
    Replies:
    1
    Views:
    4,566
    iksrazal
    Apr 25, 2004
  3. Replies:
    7
    Views:
    6,682
    Alex Molochnikov
    Feb 23, 2005
  4. salam123

    Onmouse over

    salam123, Feb 24, 2011, in forum: .NET
    Replies:
    0
    Views:
    979
    salam123
    Feb 24, 2011
  5. OnMouse

    , Mar 21, 2005, in forum: Javascript
    Replies:
    1
    Views:
    98
    Zifud
    Mar 21, 2005
Loading...

Share This Page