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 ";
}
}
}