Add a prompt box to the delete button of the gridview

Source: Internet
Author: User
Today, I modified the add method in the delete button prompt box in the gridview. Previously, the cell was added when I added the prompt box. Therefore, a prompt dialog box is displayed when I clicked the blank area in the cell, now I have found another method which is better. You can only add the button in it. I am using imagebuttom. The added code is as follows: protected void gridview1_rowdatabound (Object sender, gridviewroweventargs E)
{
// Only data rows are bound to Data.
If (E. Row. rowtype = datacontrolrowtype. datarow)
{
Imagebutton btndel = E. Row. cells [1]. controls [0] As imagebutton;
Btndel. Attributes. Add ("onclick", "define Crip: Return confirm ('Are you sure you want to delete the subscription? ')");
}
}

Cells are cells, controls is controls, and controls [0] represents the first control. I am not very clear about the as here, but it seems that a reference to a specified control is created, then, attributes are added to the control through this reference.

At the same time, there are some other problems with the gridview. For example, if the read data is 1 and 0, you want to convert it to male and female. In the past, I thought it was necessary to implement it through judgment in an SQL statement, or convert it when I read the able in the business layer. Now I found that this rowdatabound method can be easily implemented. Protected void gridview1_rowdatabound (Object sender, gridviewroweventargs E)
{
// Only data rows are bound to Data.
If (E. Row. rowtype = datacontrolrowtype. datarow)
{
If (E. Row. cells [0]. Text. Trim () = "1 ")
{
E. Row. cells [0]. Text = "male ";
}
Else
{
E. Row. cells [0]. Text = "female ";
}
}
}

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.