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. Advertisements

  2. Your post went unanswered. Have you resolved this issue?
     
    Alvin Bruney [MVP], Mar 2, 2004
    #2
    1. Advertisements

  3. Jairo Nieto

    Jairo Nieto Guest

    Nope, i havent been able to solve it :(

     
    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
     
    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], 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 :)

     
    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
     
    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?

     
    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
     
    Alvin Bruney [MVP], Mar 3, 2004
    #9
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.