Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have to put delete button in gridview without using templatefield.

i am in very big difficulty .please help me.
Posted

use a CommandField and set the ShowDelete property to true

ASP.NET
<asp:commandfield ShowDeleteButton="true" />
 
Share this answer
 
v2
hey refer below link..
Hope it will helpful.
ASP.NET GridView delete confirmation using asp:CommandField[^]

Happy Coding,
Happy New Year.
:):D
 
Share this answer
 
XML
<asp:GridView ID="GridView1" runat="server" OnRowDeleted="GridView1_RowDeleted">
           <Columns>

               <asp:CommandField ShowDeleteButton="true" />
           </Columns>
       </asp:GridView>



Fire RowDeleted events
 
Share this answer
 
bgcolor="#9999FF"><code><code><pre lang="HTML"><pre lang="HTML"></pre></pre>



<asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" width="100%" xmlns:asp="#unknown">
ShowFooter="True" BackColor="#CCCCCC" BorderColor="#999999" BorderWidth="3px"
CellPadding="4" CellSpacing="2" DataKeyNames="code" Style="color: #FFC080" ForeColor="Black"
OnRowCommand="doDelete">
<footerstyle backcolor="#666699">
<rowstyle backcolor="White">
<selectedrowstyle backcolor="#6699FF" font-bold="True" forecolor="White" />
<pagerstyle backcolor="#284775" borderstyle="None" borderwidth="1px" font-size="13px">
ForeColor="White" Height="10px" HorizontalAlign="Center" VerticalAlign="Middle"
Wrap="True" />
<headerstyle backcolor="Black" forecolor="White" cssclass="text" font-bold="True">
Wrap="True" />
<pagersettings visible="true">
<columns> <%--شماره--%>
<asp:templatefield headertext="کد تدریس">
<footertemplate>
<asp:literal id="lit" runat="server">

<itemtemplate>
<asp:literal id="lit_number" runat="server" text="<%# eval("code") %>">

<itemstyle backcolor="#CCCCFF" forecolor="Black">

<%--شماره--%>
<%--نام--%>
<asp:templatefield headertext="کد تدریس">
<edititemtemplate>
<asp:textbox id="edit_name" runat="server" text="<%# Bind("tadrisName") %>" height="20px">
Width="88px">

<footertemplate>
<asp:textbox id="txt_name" runat="server" width="86px" height="20px">

<itemtemplate>
<%#Eval("tadrisName")%>

<itemstyle backcolor="#CCCCFF" forecolor="Black">

<%--نام--%>

<%-- دكمه هاي انصراف وویرایش --%>
<asp:commandfield buttontype="Button" canceltext="انصراف" edittext="ویرایش" showeditbutton="True">
UpdateText="ویرایش" HeaderText="ویرایش">
<controlstyle backcolor="#CCCCFF" font-names="Tahoma" font-size="X-Small" forecolor="Black">
BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" />
<itemstyle cssclass="header_grid" forecolor="Black">

<%-- حذف --%>
<asp:templatefield headertext="حذف" showheader="False" itemstyle-forecolor="#DEDFDE">
<itemtemplate>
<asp:button id="btnRemove" runat="server" causesvalidation="False" commandname="Delete">
Text="delet" OnClientClick="return confirm('?آیا مایل به delet این پست هستید');" />

<controlstyle backcolor="#CCCCFF" bordercolor="Black" borderstyle="Solid" borderwidth="1px">
Font-Names="Tahoma" Font-Size="X-Small" ForeColor="Black" />
<itemstyle cssclass="header_grid" forecolor="Black">

<asp:templatefield headertext="حذف انتخابي" itemstyle-forecolor="#DEDFDE">
<footertemplate>
<asp:button commandname="Delete1" text="حذف" id="btnRemove1" runat="server" borderstyle="Solid">
OnClientClick="return confirmDelete();" BorderWidth="1px" BackColor="#DEDFDE"
Font-Names="Tahoma" Font-Size="11px" CssClass="menu" />

<itemtemplate>
<asp:checkbox id="ChkRemove" runat="server">

<itemstyle backcolor="#999999" horizontalalign="Center" bordercolor="White">
<headerstyle backcolor="Black" horizontalalign="Center" />
<controlstyle backcolor="#9999FF" bordercolor="White" borderstyle="Solid" borderwidth="1px">
ForeColor="Red" />
<footerstyle backcolor="#999999" horizontalalign="Center">

<%--<asp:buttonfield buttontype="Button" commandname="btnselect" text="انتخاب" headertext="دکمه انتخاب " />--%>
</headerstyle>






 
Share this answer
 
v2
XML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton runat="server" ID="lnkDelete" CommandArgument='<%#Eval("ID-through you are delete record") %>'
                            CommandName="cmdDelete"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>




This way you are used to delete button in grid view & fire rowCommand event in codebehind....
 
Share this answer
 
Comments
prashant patil 4987 1-Jan-13 0:53am    
hey kapil.. he want to put delete button without using template field in grid view and your solution is with template Field. Read Question again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900