DataGrid deletion confirmation and item color Alternation

Source: Internet
Author: User

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.

 

 

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.