AJAX::Edit Update Delete Using Accordion Control Using EntityFrameWork

SomeTimes We need to use accordion only to edit update delete

for that, this is the code:

In .aspx Page:

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head id="Head1" runat="server">
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<style type="text/css">
background-color: Gray;
filter: alpha(opacity=80);
opacity: 0.8;
z-index: 10000;
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<asp:Button ID="btnShow" runat="server"
onclick="btnShow_Click" Text="Click here to see accordion" />
<cc1:Accordion ID="Accordion1" runat="server"
FadeTransitions="true" RequireOpenedPane="false"
ContentCssClass="accordionContent" onitemcommand="Accordion1_ItemCommand">
<HeaderTemplate><%# Eval("Description") %>
<asp:Image ID="btnImg" ImageUrl='<%#Eval("Image") %>'
runat="server" Height="100" />
<br />
<asp:Label id="lbl1" Text="Features :"
style="font-weight:bold; color:Blue" runat="server" />
<%# Eval("Feature") %>
<br />
<asp:Label id="lbl2" Text="Vendor:"
style="font-weight:bold; color:Blue" runat="server" />
<%# Eval("Seller") %>
<br />
<asp:Label id="lb3" Text="Price:"
style="font-weight:bold; color:Blue" runat="server" />
<%# Eval("Price") %>
<br />
<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%#Eval("Id") %>' CommandName="Edit">Edit</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CommandArgument='<%#Eval("Id") %>' CommandName="Delete">Delete</asp:LinkButton>
<asp:Label ID="lblresult" runat="server"/>
<asp:Button ID="btnShowPopup" runat="server" style="display:none" />
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlpopup"
CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="209px" Width="400px" style="display:none">
<table width="100%" style="border:Solid 3px #D55500; width:100%; height:100%" cellpadding="0" cellspacing="0">
<tr style="background-color:#D55500">
<td colspan="2" style=" height:10%; color:White; font-weight:bold; font-size:larger" align="center"> Details</td>
<asp:Label ID="lblID" Font-Bold="true" ForeColor="Green" runat="server"></asp:Label>
<asp:Image ID="Image1" runat="server" Height="100" Width="100"/></td></tr>
<asp:TextBox ID="tb2" runat="server" Text="Label"></asp:TextBox></td></tr>
<asp:TextBox ID="tb3" runat="server" Text="Label"></asp:TextBox></td></tr>
<asp:TextBox ID="tb4" runat="server" Text="Label"></asp:TextBox></td></tr>
<asp:Button ID="ButtonUpdate" runat="server" OnClick="Update" Text="Update"/>
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />



.csharpcode, .csharpcode pre
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
background-color: #f4f4f4;
width: 100%;
margin: 0em;
.csharpcode .lnum { color: #606060; }

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

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    static int ItemNo;
    protected void btnShow_Click(object sender, EventArgs e)
        DatabaseModel.DatabaseEntities obj = new DatabaseModel.DatabaseEntities();
        var x = (from n in obj.Items
                 select n);
        Accordion1.DataSource = x;
    protected void Accordion1_ItemCommand(object sender, CommandEventArgs e)
        ItemNo = Convert.ToInt32(e.CommandArgument);
        DatabaseModel.DatabaseEntities obj = new DatabaseModel.DatabaseEntities();
        if (e.CommandName == "Edit")
            Class1 cls = new Class1();
            var x = (from n in obj.Items
                     where n.Id == ItemNo
                     select new
            lblID.Text = x.Description;
            Image1.ImageUrl = x.Image;
            tb2.Text = x.Feature;
            tb3.Text = x.Seller;
            tb4.Text = x.Price;
        else if (e.CommandName == "Delete")
            var x = (from n in obj.Items where n.Id == ItemNo select n).FirstOrDefault();
            btnShow_Click(sender, e);
    public void Update(object sender, EventArgs e)
        DatabaseModel.DatabaseEntities obj = new DatabaseModel.DatabaseEntities();
        var x = (from n in obj.Items where n.Id == ItemNo select n).FirstOrDefault();
        if (x != null)
            x.Description = lblID.Text;
            x.Feature = tb2.Text;
            x.Seller = tb3.Text;
            x.Price = tb4.Text;
            btnShow_Click(sender, e);

DownLoad SampleCode


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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s