DataGrid deletion confirmation and item color Alternation
Hbzxf (Hao)
Http://www.cnblogs.com/hbzxf
Sometimes, when we need to delete the data corresponding to items in the DataGrid, a confirmation dialog box needs to be popped up to prompt the user. In fact, this function is very simple. You can try the following code, another trick is to test the effect of changing colors in the items in the DataGrid.
Private void dg_itemdatabound (Object sender, datagriditemeventargs E)
{
If (E. Item. itemtype = listitemtype. Item | E. Item. itemtype = listitemtype. alternatingitem)
{
// Confirm deletion
Linkbutton delbttn = (linkbutton) E. Item. cells [1]. controls [0];
Delbttn. Attributes. Add ("onclick", "javascript: Return confirm ('Confirm to delete" + E. Item. cells [4]. Text + "? ');");
// Alternate colors
E. Item. Attributes. Add ("onmouseover", "This. style. backgroundcolor = 'seashel '");
If (E. Item. itemtype = listitemtype. item)
{
E. Item. Attributes. Add ("onmouseout", "This. style. backgroundcolor = '# ffff '");
}
If (E. Item. itemtype = listitemtype. alternatingitem)
{
E. Item. Attributes. Add ("onmouseout", "This. style. backgroundcolor = 'seashel '");
}
}
}
Thanks to my friends.XiaolinHe provides technical support and is an outstanding software engineer.