Click here to Skip to main content
13,559,305 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
i have to put delete button in gridview without using templatefield.

i am in very big difficulty .please help me.
Posted 31-Dec-12 5:26am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

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>






  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

<asp:GridView ID="GridView1" runat="server" OnRowDeleted="GridView1_RowDeleted">
           <Columns>

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



Fire RowDeleted events
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

<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....
  Permalink  
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

hey refer below link..
Hope it will helpful.
ASP.NET GridView delete confirmation using asp:CommandField[^]

Happy Coding,
Happy New Year.
:):D
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

use a CommandField and set the ShowDelete property to true

<asp:commandfield ShowDeleteButton="true" />
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.180515.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100