c# - How to hide the auto generated delete button in GridView -


how hide auto generated delete button in gridview. unable make delete button invisible. while making invisible of delete button cancel button not getting invisiable.

cancel button getting invisible

 <asp:gridview id="gvcompanies" runat="server" cssclass="mydatagrid" pagerstyle-cssclass="pager"             headerstyle-cssclass="header" rowstyle-cssclass="rows"             allowpaging="true" onpageindexchanging="gvcompanies_pageindexchanging"  autogeneratecolumns="false" emptydatatext="no records found" onrowediting="gvcompanies_rowediting" autogenerateeditbutton="true" onrowupdating="gvcompanies_rowupdating" onrowcancelingedit="gvcompanies_rowcancelingedit" onrowdeleting="gvcompanies_rowdeleting" autogeneratedeletebutton="true" onrowdatabound="gvcompanies_rowdatabound" >             <columns>              <asp:templatefield headertext="s no.">               <itemtemplate>                  <asp:label id="lblid" runat="server" text='<%#eval ("id")%>'></asp:label>                      </itemtemplate>                      </asp:templatefield>   <asp:templatefield headertext="company" itemstyle-forecolor="black"> <itemtemplate>      <a href='services.aspx?companyid=<%#eval("id")%>'> <asp:label id="lblcompany" runat="server" text='<%# eval("company")%>'/>          </a> </itemtemplate> <edititemtemplate> <asp:textbox id="txtcompany" runat="server" text='<%# eval("company")%>'/> </edititemtemplate>              </columns>               <emptydatatemplate>               <table cellspacing="0" rules="all" border="0" style="border-collapse: collapse;">             <tr style="color: white; background-color: #3ac0f2;">                 <th scope="col" style="width: 150px;">                     sl no                 </th>                 <th scope="col" style="width: 150px;">                     company                 </th>                 <th scope="col" style="width: 100px;">                     company code                 </th>                 <th scope="col" style="width: 100px;">                     address                 </th>             </tr>             <tr>                 <td colspan="99" align = "center">                     no records found search criteria.                 </td>             </tr>         </table>     </emptydatatemplate>         </asp:gridview>     if (e.row.rowtype == datacontrolrowtype.datarow)                 {                     // hide edit button when condition true                     // example, row contains property                      if (loggedinuser != "kernel")                 {                      e.row.cells[0].controls[2].visible = false;                   }                   } 

there 2 options hide or show specific column in gridview

option 1: using cells index

 protected void gridview1_rowcreated(object sender, gridviewroweventargs e)         {           if (e.row.rowtype == datacontrolrowtype.datarow)                 {                 if("your condition")                   {                      e.row.cells[0].control[0].visible = false;//or true                     }                  }                  } 

option 2: looping through gridview row controls collections

protected void gridview1_rowcreated(object sender, gridviewroweventargs e)     {               foreach (tablerow row in gridview1.controls[0].controls)             {              if("your condition")                       {                       row.cells[0].control[0].visible = false;                       }             }             } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -