AJAX Modal Popup Extender for Gridview Edit Update Delete

Code in ASPX page:

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head id="Head1" runat="server">
<style type="text/css">
.modalBackground {
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
<asp:GridView ID="GridView1" runat="server"
CellPadding="4" ForeColor="#333333" GridLines="None">
<asp:BoundField DataField="EmpNo" ReadOnly="true"
<asp:BoundField DataField="EmpName" HeaderText="Empname" />
<asp:BoundField DataField="EmpJob" HeaderText="EmpJob" />
<asp:BoundField DataField="EmpSal" HeaderText="EmpSal" />
<asp:TemplateField HeaderText="Edit">
<asp:LinkButton ID="LinkButton1" runat="server"
<AlternatingRowStyle BackColor="White" />
<FooterStyle BackColor="#990000" Font-Bold="True"
ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True"
ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333"
HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True"
ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
<br />
<asp:Button ID="Button1" runat="server" Text="Button"
style="display:none" />
<asp:ModalPopupExtender ID="Button1_ModalPopupExtender"
runat="server" DynamicServicePath="" Enabled="True"
PopupControlID="Panel1" TargetControlID="Button1"
CancelControlID="Button3" BackgroundCssClass="modalBackground">
<asp:Panel ID="Panel1" runat="server"
BorderColor="#990033" BorderWidth="2px">
<table class="style1" bgcolor="#FFFFCC">
<td align="center" bgcolor="#FFFF99" colspan="2"
style="color: #FFFFFF; font-weight: 700;
font-size: large; background-color: #990033;">
Edit Details</td>
<td class="style5">
<td class="style5">
<asp:Label ID="Id" runat="server"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server">
<asp:TextBox ID="TextBox3" runat="server">
<asp:TextBox ID="TextBox4" runat="server">
<asp:Button ID="Button2" runat="server"
onclick="Button2_Click" Text="Update" />
<asp:Button ID="Button3" runat="server" Text="Cancel" />
<td colspan="2" style="background-color: #990033">

Code Behind:

DatabaseModel.DatabaseEntities obj = new DatabaseModel.DatabaseEntities();
    Class1 obj3 = new Class1();
    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
    public void GetData()
        var x = (from n in obj.Emps
                 select n);
        GridView1.DataSource = x;
    public void ShowPopup(object sender, EventArgs e)
        LinkButton lnk = sender as LinkButton;
        GridViewRow Row = (GridViewRow)lnk.NamingContainer;
        Id.Text = Row.Cells[0].Text;
        TextBox2.Text = Row.Cells[1].Text;
        TextBox3.Text = Row.Cells[2].Text;
        TextBox4.Text = Row.Cells[3].Text;
    protected void Button2_Click(object sender, EventArgs e)
        DatabaseModel.Emp emp = new DatabaseModel.Emp();
        int id = Convert.ToInt32(Id.Text);
        DatabaseModel.DatabaseEntities Model = new DatabaseModel.DatabaseEntities();
        var x = (from n in Model.Emps
                 where n.EmpNo == id
                 select n).FirstOrDefault();
        if (x != null)
            x.EmpName = TextBox2.Text;
            x.EmpJob = TextBox3.Text;
            x.EmpSal = Convert.ToDecimal(TextBox4.Text);


if you are getting the following error:

A potentially dangerous Request.Path value was detected from the client(&).

Please click on following link


One thought on “AJAX Modal Popup Extender for Gridview Edit Update Delete

  1. This is awesome!! really helpful for me. Thanks for sharing with us. Following links also helped me to complete my task.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s