AboutGridview"Convert this fieldTemplatefield"
ProcessingCommandfieldWhen the field is notIDAttribute, so some operations are difficult, suchCommandfieldIt is troublesome to delete, edit, or perform other operations on fields, although you can write the following code:
(Gridview1.Columns [Index]As Commandfield). Showdeletebutton = false;
In this way, the delete button can be hidden.,However, the delete button of the entire column is hidden.,That is to say,This column in each row is hidden.,However, this column of a row is required to be hidden.,This is troublesome..Because I useGridview1_rowdataboundMethod,You can do this in it.: E. Row. cells [Index],In this way, you can find a column in a row.,But it cannot.As Commandfield,So it cannot be switched.,Found online,Although the exact answer to this question cannot be found,However, when some people solve other problems,Is to convert a certain type of fieldTemplatefieldTo process,So I will Commandfield Converted , Sure enough. , CodeAs follows: , You can also add deletion confirmation JS Code :
< ASP : Templatefield Showheader= "False">
<Itemtemplate>
<ASP:Linkbutton ID= "Sel" Runat= "Server" Causesvalidation= "False" Commandname= "Select" Text=" Select">
</ASP:Linkbutton>
<ASP:Linkbutton ID= "Del" Onclientclick= "Return confirm (' Are you sure you want to delete? ')" Runat= "Server" Causesvalidation= "False" Commandname= "Delete" Text=" Delete">
</ASP:Linkbutton>
</Itemtemplate>
</ASP:Templatefield>
In this case, it is easy to find a control.,Write it in the background like thisOKNow(The selected event will not change.):
If (...)
{
(E. Row. cells [5]. findcontrol ("Del")As Linkbutton). Visible =False;
}