Add Javascript in HeadCodeAs follows:
<SCRIPT lang = JavaScript>
Function sel (I) // move the mouse up and then execute
{
Eval (I + ". style. Background = '# cccc66'"); // you can change the color of a row.
Eval (I + ". style. cursor = 'hand'"); // move the cursor up and turn it into a hand shape
}
Function unsel (I) // run after the mouse leaves
{
Eval (I + ". style. Background = ''");
}
Function clicktr (I)
{
Eval (I + ". style. Background = ''");
Window. Open ("Edit. aspx? Param = "+ I," modify "," Height = 490, width = 710, resizable = No, scrollbars = No, status = No, toolbar = No,
Menubar = No, location = No, Left = 50, Top = 50 ");
}
</SCRIPT>
In the itemdatabound event of the DataGrid (when data is bound:
Private void maid (Object sender, system. Web. UI. webcontrols. datagriditemeventargs E)
{
If (E. Item. itemtype! = Listitemtype. header)
{
String id = E. item. cells [0]. text; // The first column here is the ID value in data binding (it is convenient to PASS Parameters on the modification page. If there are multiple parameters, you can add them as needed !)
E. Item. Attributes. Add ("ID", ID );
E. Item. Attributes. Add ("onmouseover", "sel (" + ID + ")");
E. Item. Attributes. Add ("onmouseout", "unsel (" + ID + ")");
E. Item. Attributes. Add ("onclick", "clicktr (" + ID + ")");
}
}
********* *************************************//
However, the preceding method is inconvenient. if you add a template column in The DataGrid to provide you with the selection operation (such as deleting the selected column ),
In this case, the above method will cause a new window to pop up every time you select the checkbox (The onclick event is triggered)
Relatively poor solution:
Change the row-based attributes to column-based. Remove the template column and add attributes to all columns.
For example, if the template is listed in the 6th column, you can modify the CS file in this way.
Private void maid (Object sender, system. Web. UI. webcontrols. datagriditemeventargs E)
{
If (E. Item. itemtype! = Listitemtype. header)
{
String Bm = E. Item. cells [0]. text;
For (INT I = 0; I <5; I ++)
{
E. Item. cells [I]. Attributes. Add ("ID", "a" + I. tostring () + BM );
E. Item. cells [I]. Attributes. Add ("onmouseover", "sel (" + I. tostring () + "," + BM + ")");
E. Item. cells [I]. Attributes. Add ("onmouseout", "unsel (" + I. tostring () + "," + BM + ")");
E. Item. cells [I]. Attributes. Add ("onclick", "clicktr (" + BM + ")");
}
}
}
In JavaScript code:
Function sel (I, ID)
{
For (var j = 0; j <5; j ++)
{Eval ("A" + J. tostring () + ID + ". style. background = '# cccc66' "); EVAL (" A "+ J. tostring () + ID + ". style. cursor = 'hand '");
}
}
Function unsel (I, ID)
{
For (var j = 0; j <5; j ++)
{Eval ("A" + J. tostring () + ID + ". style. Background = ''");
}
}
Function clicktr (I)
{
For (var j = 0; j <5; j ++)
{
Eval ("A" + J. tostring () + I + ". style. Background = ''");
Window. Open ("Edit. aspx? Param = "+ I," modify "," Height = 490, width = 710, resizable = No, scrollbars = No, status = No, toolbar = No,
Menubar = No, location = No, Left = 50, Top = 50 ");
}
}