Posted by : Anwar Hossain
Category : How to use ajax toolkit in asp.net C#

How to use Ajax ConfirmButtonExtender in asp.net using c#

Dear viewers I will show how to use ASP.Net AJAX Control Toolkit ConfirmButtonExtender at the time of gridview row data deleting . In this case I have used virtual data to show this operation but real time data will be deleted from database.I have also used Link button instead of asp asp:CommandField .At first drag ConfirmButtonExtender on the page and assign the link button to ConfirmButtonExtender using it’s TargetControlID Properties and write warning value it’s ConfirmText properties .

Use ajax ConfirmButtonExtender in ASP.NET C#

HTML

<%@ RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="asp"%>


 <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>Delete Confirmation</title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <asp:GridView ID="Studentlist" CssClass="Grid" runat="server" OnRowDeleting="OnRowDeleting"
  AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None">
  <AlternatingRowStyle BackColor="White" />
  <Columns>
  <asp:BoundField DataField="StudentName" HeaderText="StudentName" />
  <asp:BoundField DataField="Address" HeaderText="Address" />
  <asp:BoundField DataField="Phone" HeaderText="Phone" />
  <asp:BoundField DataField="JoingDate" HeaderText="JoingDate" />
  <asp:TemplateField>
  <ItemTemplate>
  <asp:LinkButton ID="lnkDelete" runat="server" CommandName="Delete">Delete</asp:LinkButton>
  <asp:ConfirmButtonExtender ID="DeleteConfirmation" runat="server" ConfirmText="Are you sure to delete this Data ...?"
  Enabled="True" TargetControlID="lnkDelete">
  </asp:ConfirmButtonExtender>
  </ItemTemplate>
  </asp:TemplateField>
   </Columns>
  <EditRowStyle BackColor="#2461BF" />
  <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
  <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
  <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
  <RowStyle BackColor="#EFF3FB" />
  <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
  <SortedAscendingCellStyle BackColor="#F5F7FB" />
  <SortedAscendingHeaderStyle BackColor="#6D95E1" />
  <SortedDescendingCellStyle BackColor="#E9EBEF" />
  <SortedDescendingHeaderStyle BackColor="#4870BE" />
  </asp:GridView>
  <asp:ScriptManager ID="ScriptManager1" runat="server">
  </asp:ScriptManager>
  </div>
  </form>
</body>
</html>

NAME SPACES

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

CODE BEHIND

protected void Page_Load(object sender, EventArgs e)
  {
 
  if (!IsPostBack)
  {
 
  if (!Page.IsPostBack)
  {
  ViewState["StudentList"] = GetStudentList();
  BindGrid();
 
 
 
  }
 
  }
 
  }
 
 
  protected void BindGrid()
  {
  Studentlist.DataSource = ViewState["StudentList"];
  Studentlist.DataBind();
  }
  static DataTable GetStudentList()
  {
 
  //I  Have Created Virtual table
 
  DataTable table = new DataTable();
  table.Columns.Add("StudentName", typeof(string));
  table.Columns.Add("Address", typeof(string));
  table.Columns.Add("Phone", typeof(string));
  table.Columns.Add("JoingDate", typeof(DateTime));
 
 
  // Now have created some row to fill the the datatable
 
  table.Rows.Add( "Samim", "Dhaka","01856587548", "11/5/2007");
  table.Rows.Add("Ahsan", "Chittagong", "01856587548","12/ 5/2007");
  table.Rows.Add("Nirub", "Sylhet", "01856587544", "11/10/ 2007");
  table.Rows.Add("Zaman", "Rajsahi", "01856587578", "11 /15/ 2007");
  table.Rows.Add("Habib", "Barisal", "01856587548", "11 /5 / 2010");
  table.Rows.Add("Roman", "Chandpur", "01856587548", "11 /5 / 2010");
  table.Rows.Add("Iqbal Hossain", "Noakhali", "01856587548", "11 /5 / 2010");
  return table;
  }
 
  protected void OnRowDeleting(object sender, GridViewDeleteEventArgs e)
  {
  int index = Convert.ToInt32(e.RowIndex);
  DataTable dt = ViewState["StudentList"] as DataTable;
  dt.Rows[index].Delete();
  ViewState["dt"] = dt;
  BindGrid();
  }

Out Put

ajaxtoolkit-delete-confirmation-extender

Output

ajaxtoolkit-delete-confirmation-extender_result



Realted Article Headline

How to use TextBoxWatermarkExtender in asp.net using c#
How to use Ajax AutoCompleteExtender control in asp.net using c#
How to use Ajax Collapsible panel control in asp.net c#
How to use ASP.Net AJAX Control Toolkit ModalPopupExtender Control in asp.net c#
how to add an Ajax Control Toolkit Accordion to a page
How to use html editor Ajax control toolkit example in c#
How to use Ajax ConfirmButtonExtender in asp.net using c#
how to use ajax calendar extender in asp net c#
How to use ajax toolkit FilteredTextBox Control in c#

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection