Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:15pm
Edited 17-Feb-12 23:17pm
v2

1 solution

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

Solution 1

<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")%>">
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 at 18-Feb-12 6:05am
   
thank u sir but here when i click the cancel .the data is deleting . what i to do?
Uma Shankar Patel at 18-Feb-12 6:10am
   
<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)



Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 18 Feb 2012
Copyright © CodeProject, 1999-2014
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