<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default1.aspx.cs"
Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit"
TagPrefix="ajaxToolkit" %>
<!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 id="head" runat="server">
<title>Delete Confirm Example</title>
<script type="text/javascript">
// keeps track of the delete button for the row
// that is going to be removed
var _source;
// keep track of the popup div
var _popup;
function showConfirm(source){
this._source = source;
this._popup = $find('mdlPopup');
// find the confirm ModalPopup and show it
this._popup.show();
}
function okClick(){
// find the confirm ModalPopup and hide it
this._popup.hide();
// use the cached button as the postback source
__doPostBack(this._source.name, '');
}
function cancelClick(){
// find the confirm ModalPopup and hide it
this._popup.hide();
// clear the event source
this._source = null;
this._popup = null;
}
</script>
<style>
.modalBackground {
background-color:Gray;
filter:alpha(opacity=70);
opacity:0.7;
}
.confirm{
background-color:White;
padding:10px;
width:370px;
}
</style>
</head>
<body>
<form id="form" runat="server" style="font-family: Trebuchet MS;">
<asp:ScriptManager ID="scriptManager" runat="server" />
<div>
<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblTitle" runat="server" Text="User List"
BackColor="lightblue" Width="95%" />
<asp:GridView ID="gvUsers" runat="server"
AutoGenerateColumns="false" Width="95%">
<AlternatingRowStyle BackColor="aliceBlue" />
<HeaderStyle HorizontalAlign="Left" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="FirstName"
HeaderText="FirstName" />
<asp:BoundField DataField="LastName"
HeaderText="LastName" />
<asp:BoundField DataField="Address" HeaderText="Address" />
<asp:TemplateField ControlStyle-Width="50px"
HeaderStyle-Width="60px"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button ID="btnDelete" runat="server"
OnClientClick="showConfirm(this); return false;"
OnClick="BtnDelete_Click" Text="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1"
BehaviorID="mdlPopup" runat="server"
TargetControlID="div" PopupControlID="div" OkControlID="btnOk"
OnOkScript="okClick();"
CancelControlID="btnNo" OnCancelScript="cancelClick();"
BackgroundCssClass="modalBackground" />
<div id="div" runat="server" align="center" class="confirm"
style="display: none">
<img align="absmiddle" src="Img/warning.jpg" />
Are you sure you want to delete this
item?
<asp:Button ID="btnOk" runat="server" Text="Yes" Width="50px" />
<asp:Button ID="btnNo" runat="server" Text="No" Width="50px" />
</div>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.gvUsers.DataSource = this.Users;
this.gvUsers.DataBind();
}
}
public class User
{
private int _id;
private string _firstName;
private string _lastName;
private string _Address;
// private bool _isCompleted;
public User(int id, string firstname, string lastname, string address)
{
this._id = id;
this._firstName = firstname;
this._lastName = lastname;
this._Address = address;
}
public int ID
{
get { return this._id; }
}
public string FirstName
{
get { return this._firstName; }
}
public string LastName
{
get { return this._lastName; }
}
public string Address
{
get { return this._Address; }
}
}
private System.Collections.Generic.List<User> Users
{
get
{
System.Collections.Generic.List<User> item = this.Session["Users"] as System.Collections.Generic.List<User>;
if (item == null)
{
item = new System.Collections.Generic.List<User>();
item.Add(new User(1, "santosh", "kumar", "Chandigarh"));
item.Add(new User(2, "Vinod", "kumar", "HP"));
item.Add(new User(3, "Ajay", "Chawla", "PB"));
item.Add(new User(4, "MandeepInder", "Singh", "Chandigarh"));
item.Add(new User(4, "Harpreet", "Singh", "Chandigarh"));
this.Session["Users"] = item;
}
return item;
}
}
protected void BtnDelete_Click(object sender, EventArgs e)
{
// get the gridviewrow from the sender so we can get the datakey we need
Button btnDelete = sender as Button;
GridViewRow row = (GridViewRow)btnDelete.NamingContainer;
// find the item and remove it
User itemToRemove = this.Users[row.RowIndex];
this.Users.Remove(itemToRemove);
// rebind the datasource
this.gvUsers.DataSource = this.Users;
this.gvUsers.DataBind();
}
}
A directory of ASP.NET tutorials,ASP.NET Codebook, applications, scripts, assemblies and articles for the novice to professional developer
Blog Archive
-
▼
2009
(29)
-
►
April
(9)
- How To Read xml using JQuery
- jQuery Ajax call and result XML parsing in asp.net...
- How To Include Content of One Page To another Page...
- How To Select Value of gridview row using javascri...
- how to convert web page to pdf
- ASP.NET and Ajax - using XmlHttpRequest
- How To Move Selected Record From One GridView to a...
- How To Extract Number from string
- How To create Cascade dropdownlist using asp.net c...
-
►
March
(18)
- Parent Child Relationship in Javascript
- How To Create Composite Control
- How To find control inside EmptyTemplate
- jQuery in 15 minutes
- How To Create MultiColum Dropdownlist using DropDo...
- How To Create Multi Column Dropdownlist
- How To Create control at runtime using javascript
- How to Move a Text Box on Button Click
- How To attach event to runtime created control
- How To Find Position of Span Tag
- How To add event to runtime created control -Javas...
- How To Display Hierarchical Data in the DropDownLi...
- Real World GridView: Excel-like Frozen Headers for...
- GridView Sorting And Paging
- How to create a Setup project for a Windows Servic...
- 101 LINQ Samples
- How to open ModalPopup inside ModalPopup
- How to Retrieve Hardware and softwarte information...
-
►
April
(9)
-
►
2008
(490)
-
►
December
(7)
- Creating javascript alerts in ASP.NET with UpdateP...
- ASP.net TreeView Tips and Trics
- How to make your ASP.Net label multilin
- How To Create TextBox Control Dynamically at Runti...
- How To Use RegularExpressionValidator with FileUpl...
- How To Add Multiple UserControls using RequiredFie...
- How To Make Clickable image
-
►
October
(11)
- How To Call .net Webservice using Javascript
- Calling page methods from javascript using ASP.NET...
- How To Use Web Service Behavior in an ASP.NET Page...
- How To Load xml string into DataSet
- How to convert from XmlTextWriter to String?
- Error: Timeout expired. The timeout period elapsed...
- Using an XML file for your ASP.NET settings
- Two approaches to redirection in ASP.NET
- read, write and save values in app.config file
- Adding tooltips to GridView headers
-
►
December
(7)
Thursday, April 3, 2008
GridView Confirm When Delete.
Labels:
ASP.NET
Subscribe to:
Post Comments (Atom)
|
Over the years I have collected some best asp.net code while googling........I hope
this information is as useful to you as it has been for me("If you find my post
contains a reference to a third party World Wide Web site, I am providing this information
as a convenience to you.I cannot make any representations regarding the quality,safety,
or suitability of any software or information found there")
|








0 comments:
Post a Comment