Click here to Skip to main content
Sign Up to vote bad
good
See more: C#3.0
hello,
I want to delete the single row in gridview with using template control.I am using oracle database .when i click the delete i want to show the confirmation message box.
Thanks
Posted 17 Feb '12 - 23:15
Edited 17 Feb '12 - 23:17


1 solution

<asp:gridview id="GridView1" runat="server" allowpaging="True" xmlns:asp="#unknown">
        AutoGenerateColumns="False" 
        DataSourceID="cmmentsdatasource" Width="992px" onrowcommand="rowcmd" 
        DataKeyNames='id' CellPadding="0" CssClass="style51" ForeColor="#333333">
        
        
 
        <rowstyle backcolor="#EFF3FB" font-bold="False" height="20px"></rowstyle>
        <columns>
        <asp:templatefield>
                 <itemtemplate>
                 <asp:linkbutton id="lb1" runat="server" causesvalidation="false" onclientclick="return confirm('Are You sure to delete this entry')" text="Delete" commandargument="<%#Eval("id")%>"></asp:linkbutton>
                 </itemtemplate>
                 
                 </asp:templatefield>
                
         <asp:boundfield datafield="id" headertext="ID" sortexpression="id" />
            <asp:boundfield datafield="senderid" headertext="SenderId">
                SortExpression="senderid" />
            <asp:boundfield datafield="sendername" headertext="SenderName">
                SortExpression="sendername" />
            <asp:boundfield datafield="comments" headertext="Comments">
                SortExpression="comments" />
            <asp:boundfield datafield="date" headertext="Date" sortexpression="date" />
        </asp:boundfield></asp:boundfield></asp:boundfield></columns>
       
        
        <footerstyle backcolor="#507CD1" font-bold="True" forecolor="White">
       </footerstyle>
       
        
 
        <pagerstyle backcolor="#2461BF" forecolor="White" horizontalalign="Center">
       </pagerstyle>
       
 
        <selectedrowstyle backcolor="#D1DDF1" font-bold="True" forecolor="#333333">
        </selectedrowstyle>
       
        
 
        <headerstyle backcolor="#507CD1" font-bold="True" forecolor="White">
            Font-Size="Small" Height="20px">
        </headerstyle>
       
        
        <editrowstyle backcolor="#2461BF"></editrowstyle>
        
 
        <alternatingrowstyle backcolor="White"></alternatingrowstyle>
    </asp:gridview>
 
on row command event
 
protected void rowcmd(object sender, GridViewCommandEventArgs e)
    {
      // create and open DB connection
        try
        {
           
            Int32 id = Convert.ToInt32(e.CommandArgument);
            string comm = "Delete from tblComments where id=@id";
            SqlCommand cmd = new SqlCommand(comm, Db.GetConnection());
            cmd.Parameters.AddWithValue("id", id);
            cmd.ExecuteNonQuery();
           GridView1.DataBind();
        }
        catch (Exception ex)
        {
        }
 
    }
 
 
O
  Permalink  
Comments
Ramadurai U - 18 Feb '12 - 6:05
thank u sir but here when i click the cancel .the data is deleting . what i to do?
Uma Shankar Patel - 18 Feb '12 - 6:10
<asp:linkbutton id="lb1" runat="server" causesvalidation="false" onclientclick="return confirm('Are You sure to delete this entry')" text="Delete" commandname="delete" commandargument="<%#Eval("id")%>"> and use protected void rowcmd(object sender, GridViewCommandEventArgs e) { // create and open DB connection try { if(e.Commandname=="delete") { Int32 id = Convert.ToInt32(e.CommandArgument); string comm = "Delete from tblComments where id=@id"; SqlCommand cmd = new SqlCommand(comm, Db.GetConnection()); cmd.Parameters.AddWithValue("id", id); cmd.ExecuteNonQuery(); GridView1.DataBind(); } } catch (Exception ex) { } }

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 353
1 Sergey Alexandrovich Kryukov 138
2 Mohammed Hameed 123
3 Santhosh G_ 113
4 Ron Beyer 64
0 Sergey Alexandrovich Kryukov 8,266
1 OriginalGriff 6,516
2 CPallini 3,533
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 18 Feb 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid