Datagrid control to change the row color on Mouse click event

Discussion in 'ASP .Net' started by karunakar, Jan 31, 2005.

  1. karunakar

    karunakar Guest

    Hi All,

    I want to deselect the row in DATAGRID. in ASP.NET application.
    I was alredy selected in datagrid row .I want to change another row in same
    datgrid .
    Here in my datagrid was selected in Multiple rows. when ever i select the
    particular row that time it can be selected .Next time i want to choose
    another datagrid row that time in My application first row also
    hilighted.(Here Multiple
    rows selected) that should not happen

    I want to Deselect first row in DataGrid.

    I was done like this :


    <script language="JavaScript">
    var lastColorUsed;
    function prettyDG_changeBackColor(row, highlight)
    {
    if (highlight)
    {
    lastColorUsed = row.style.backgroundColor;

    row.style.backgroundColor = 'pink';
    }
    else
    row.style.backgroundColor = lastColorUsed;
    }
    </script>


    if(e.Item.ItemType==ListItemType.Item ||
    e.Item.ItemType==ListItemType.AlternatingItem)

    {

    e.Item.Attributes["onmouseover"] =
    "javascript:prettyDG_changeBackColor(this, true);";

    e.Item.Attributes["onmouseout"] = "javascript:prettyDG_changeBackColor(this,
    false);";

    e.Item.Attributes["onclick"] = "javascript:prettyDG_changeBackColor(this,
    true);";

    }



    Thank you
    Karunakara Rao
     
    karunakar, Jan 31, 2005
    #1
    1. Advertising

  2. Karunakara,

    First of all you should be using different colors for onclick and
    onmouseover events. Otherwise you will have 2 pink records: one that is
    selected and another one where the mouse is. Than you can leave
    prettyDG_changeBackColor for onmouseover and onmouseout event and use the
    following for onclick:

    <script language="JavaScript">
    var lastRowSelected;
    var lastRowSelectedColorUsed;
    function prettyDG_changeBackColor(row)
    {
    var color = lastRowSelectedColorUsed;
    lastRowSelectedColorUsed= row.style.backgroundColor;
    row.style.backgroundColor = 'pink';
    if (lastRowSelected != null)
    lastRowSelected.backgroundColor = color;
    lastRowSelected = row;
    }
    </script>

    Eliyahu

    "karunakar" <> wrote in message
    news:...
    > Hi All,
    >
    > I want to deselect the row in DATAGRID. in ASP.NET application.
    > I was alredy selected in datagrid row .I want to change another row in

    same
    > datgrid .
    > Here in my datagrid was selected in Multiple rows. when ever i select the
    > particular row that time it can be selected .Next time i want to choose
    > another datagrid row that time in My application first row also
    > hilighted.(Here Multiple
    > rows selected) that should not happen
    >
    > I want to Deselect first row in DataGrid.
    >
    > I was done like this :
    >
    >
    > <script language="JavaScript">
    > var lastColorUsed;
    > function prettyDG_changeBackColor(row, highlight)
    > {
    > if (highlight)
    > {
    > lastColorUsed = row.style.backgroundColor;
    >
    > row.style.backgroundColor = 'pink';
    > }
    > else
    > row.style.backgroundColor = lastColorUsed;
    > }
    > </script>
    >
    >
    > if(e.Item.ItemType==ListItemType.Item ||
    > e.Item.ItemType==ListItemType.AlternatingItem)
    >
    > {
    >
    > e.Item.Attributes["onmouseover"] =
    > "javascript:prettyDG_changeBackColor(this, true);";
    >
    > e.Item.Attributes["onmouseout"] =

    "javascript:prettyDG_changeBackColor(this,
    > false);";
    >
    > e.Item.Attributes["onclick"] = "javascript:prettyDG_changeBackColor(this,
    > true);";
    >
    > }
    >
    >
    >
    > Thank you
    > Karunakara Rao
    >
    >
     
    Eliyahu Goldin, Jan 31, 2005
    #2
    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. Davisro
    Replies:
    2
    Views:
    1,351
    Jim Corey
    Apr 23, 2004
  2. =?Utf-8?B?am9qb2Jhcg==?=
    Replies:
    1
    Views:
    4,167
    wwwtar
    Oct 2, 2006
  3. =?Utf-8?B?aWdvdHlvdXJkb3RuZXQ=?=

    change row color of empty row

    =?Utf-8?B?aWdvdHlvdXJkb3RuZXQ=?=, Oct 19, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    462
    Walter Wang [MSFT]
    Oct 24, 2006
  4. Cylix
    Replies:
    0
    Views:
    121
    Cylix
    Jun 13, 2006
  5. Daniish
    Replies:
    2
    Views:
    267
    Thomas 'PointedEars' Lahn
    Jun 13, 2008
Loading...

Share This Page