example of ajax control "ConfirmButton" using asp.net with C#
ConfirmButton.aspx
<%@ Page Language="C#"
AutoEventWireup="true"
CodeFile="ConfirmButton.aspx.cs"
Inherits="ConfirmButton"
%>
<%@ Register Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit"
TagPrefix="asp"
%>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ToolkitScriptManager ID="ScriptManager1" runat="server"></asp:ToolkitScriptManager>
<asp:UpdatePanel ID="updatepnl1" runat="server">
<ContentTemplate>
<asp:GridView runat="server"
ID="gvDetails"
CssClass="Gridview"
DataKeyNames="pro_id" AutoGenerateColumns="false">
<HeaderStyle BackColor="#df5015" />
<Columns>
<asp:BoundField DataField="quantity"
HeaderText="quantity"
/>
<asp:BoundField DataField="rate"
HeaderText="rate"
/>
<asp:BoundField DataField="total"
HeaderText="total"
/>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="btnDelete"
ImageUrl="~/delete.jpeg"
Height="30px"
Width="30px"
runat="server"
/>
<asp:ConfirmButtonExtender ID="cnfbtn" TargetControlID="btnDelete"
DisplayModalPopupID="ModalPopupExtender1"
runat="server"></asp:ConfirmButtonExtender>
<asp:ModalPopupExtender ID="ModalPopupExtender1"
runat="server"
TargetControlID="btnDelete"
PopupControlID="pnlpopup"
CancelControlID="btnNo" BackgroundCssClass="modalBackground"></asp:ModalPopupExtender>
<asp:Panel ID="pnlpopup"
runat="server"
BackColor="White"
Height="100px"
Width="400px"
style="display:none">
<table width="100%"
style="border:Solid 2px #D46900; width:100%; height:100%" cellpadding="0"
cellspacing="0">
<tr style="background-image:url(Images/header.gif)">
<td style="
height:10%; color:White; font-weight:bold;padding:3px; font-size:larger; font-family:Calibri"
align="Left"
colspan="2">Confirm
Box</td>
</tr>
<tr>
<td colspan="2" align="left" style="padding:5px; font-family:Calibri">
<asp:Label ID="lblUser"
runat="server"
Text="Are you sure
you want to delete selected Record?"/>
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td>
</td>
<td align="right"
style="padding-right:15px">
<asp:ImageButton ID="btnYes" OnClick="btnYes_Click"
Height="30px"
Width="30px"
runat="server"
ImageUrl="~/yes.jpeg"/>
<asp:ImageButton ID="btnNo" runat="server"
Height="30px"
Width="30px"
ImageUrl="~/no.jpeg"
/>
</td>
</tr>
</table>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Label ID="lblresult"
runat="server"/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
ConfirmButton.aspx.cs
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data;
using
System.Data.SqlClient;
using
System.Drawing;
public partial class ConfirmButton : System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
if
(!IsPostBack)
{
BindUserDetails();
}
}
protected void BindUserDetails()
{
string
con = @"Data Source=SQLDB;Initial
Catalog=Demo;User ID=Demoh;Password=Demo1@";
string
q = "select com_id,com_logo,com_name from
pi_company";
SqlConnection conn = new
SqlConnection(con);
//connection
open
conn.Open();
//sql command
to execute query from database
SqlCommand
cmd = new SqlCommand("Select * from pi_rate", conn);
cmd.ExecuteNonQuery();
SqlDataAdapter
da = new SqlDataAdapter(cmd);
DataSet
ds = new DataSet();
da.Fill(ds);
//Binding
data to gridview
gvDetails.DataSource = ds;
gvDetails.DataBind();
conn.Close();
}
protected void btnYes_Click(object
sender, ImageClickEventArgs e)
{
string
con = @"Data Source=SQLDB;Initial
Catalog=Demo;User ID=DemoD;Password=Demo1@";
SqlConnection
conn = new SqlConnection(con);
ImageButton
btndetails = sender as ImageButton;
GridViewRow
gvrow = (GridViewRow)btndetails.NamingContainer;
Session["pro_id"]
= gvDetails.DataKeys[gvrow.RowIndex].Value.ToString();
Session["quantity"]
= gvrow.Cells[0].Text;
//getting
userid of particular row
int userid = Convert.ToInt32(Session["pro_id"]);
conn.Open();
SqlCommand
cmd = new SqlCommand("delete from pi_rate where pro_id='" +
userid+"'", conn);
int
result = cmd.ExecuteNonQuery();
conn.Close();
if
(result == 1)
{
lblresult.Text = Session["quantity"] + "
Details deleted successfully";
lblresult.ForeColor = Color.Green;
BindUserDetails();
}
}
}
0 comments :