[ASP.net] DataGrid Mouse Event handling

Source: Internet
Author: User
Asp.net|datagrid completion function is the DataGrid page selection event, mouse event, double-click event to change the color of tr. The code is very simple, just a little JS operation.

JS file: Gridcontrol.js
=============================

/*------------DataGrid mouse Event handling------------
Function: For data-bang-after mouse events
Parameter description:
Obj: Yes like this
FontColor: Font Color
BackColor: Background Color
----------------------------------------------*/

var objstate

When------------mouse passes-----------
function Onfoucsmouseover (Obj,fontcolor,backcolor)
{
if (Obj.rowindex > 0)
{
Obj.style.color = FontColor;
Obj.style.backgroundColor = BackColor;
}
}

-----------the mouse is left-----------
function Onfoucsmouseout (Obj,fontcolor,backcolor)
{
if (Obj.rowindex > 0)
{
if (obj!= objstate)
{
Obj.style.color = FontColor;
Obj.style.backgroundColor = BackColor;
}
}
}

-----------Mouse click-----------
function Onfoucsclick (Obj,fontcolor,backcolor)
{
if (Obj.rowindex > 0)
{
if (objstate!= null)
{
ObjState.style.color = "";
ObjState.style.backgroundColor = "";
}
Obj.style.color = FontColor;
Obj.style.backgroundColor = BackColor;

ObjState = obj;
}
}

-----------the mouse is double-clicked-----------
function Onfoucsdbclick (Obj,fontcolor,backcolor,openurl)
{
Parameter OpenURL is the address of the new window you want to open
if (Obj.rowindex > 0)
{
if (objstate!= null)
{
ObjState.style.color = "";
ObjState.style.backgroundColor = "";
}
Obj.style.color = FontColor;
Obj.style.backgroundColor = BackColor;

ObjState = obj;

window.open (OpenURL);
}
}

==========================================

Background data Bang Set Example:

==========================================

private void Dglist_itemdatabound (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//
if (E.item.itemindex!=-1)
{
E.item.attributes.add ("OnMouseOver", "Onfoucsmouseover" (This, ' #FFFFFF ', ' #000000 ');
E.item.attributes.add ("onmouseout", "Onfoucsmouseout" (This, ' #000000 ', ' #FFFFFF ');
E.item.attributes.add ("OnClick", "Onfoucsclick (This, ' #FFFFFF ', ' #000000 ');");
E.item.attributes.add ("OnDblClick", "Onfoucsdbclick" (This, ' #FFFFFF ', ' #000000 ', ' About:bank ');
}
}

==========================================

The foreground. aspx page calls the JS file:

<script language= "javascript" src= "Gridcontrol.js" ></script>




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.