This is a migrated thread and some comments may be shown as answers.

Rad grid not doing CRUD(Means doing nothing)

1 Answer 51 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Swapnil asked on 26 Sep 2012, 06:43 AM
I am following the post to do Automatic CRUD operation on rad grid using Entity Framework by using:

My code for Design Page:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Demo.aspx.cs" Inherits="Telerik.Demo" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
<html xmlns="">
<head id="Head1" runat="server">
    <style type="text/css">
            cursor: hand;
        .EditFormHeader td
            font-size: 14px;
            padding: 4px !important;
            color: #0066cc;
<body class="BODY" style="background-color: Black">
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
        <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="EntityDataSource1" GridLines="None"
            AllowPaging="True" AllowAutomaticUpdates="True" AllowAutomaticInserts="True"
            AllowAutomaticDeletes="True" AllowSorting="True" Width="750px" OnItemCreated="RadGrid1_ItemCreated"
            CellSpacing="0" Skin="Black">
            <PagerStyle Mode="NextPrevAndNumeric" />
                <Selecting CellSelectionMode="None"></Selecting>
            <MasterTableView DataSourceID="EntityDataSource1" AutoGenerateColumns="False" DataKeyNames="ID"
                <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
                <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                    <telerik:GridBoundColumn DataField="ID" HeaderText="ID" SortExpression="ID" UniqueName="ID"
                    <telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name"
                    <telerik:GridBoundColumn DataField="Address" HeaderText="Address" SortExpression="Address"
                    <telerik:GridBoundColumn DataField="DeptID" HeaderText="DeptID" SortExpression="DeptID"
                    <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton" />
                    <EditColumn ButtonType="ImageButton" />
            <FilterMenu EnableImageSprites="False">
        <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=Entity"
            DefaultContainerName="Entity" EnableDelete="True" EnableFlattening="False" EnableInsert="True"
            EnableUpdate="True" EntitySetName="EMPLOYEEs" EntityTypeFilter="EMPLOYEE">

Code Behind Page:

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

namespace Telerik
    public partial class Demo : System.Web.UI.Page
        Entity ent = new Entity();
        EMPLOYEE emp = new EMPLOYEE();
        protected void Page_Load(object sender, EventArgs e)
                RadGrid1.DataSourceID = null;

        public void BindGrid()
                var query5 = from employee in ent.EMPLOYEEs
                             select new
                                 ID = employee.ID,
                                 NAME = employee.NAME,
                                 ADDRESS = employee.ADDRESS,
                                 DEPTID = employee.DEPTID
                RadGrid1.DataSource = query5;

        protected void RadGrid1_ItemCreated(object sender, Web.UI.GridItemEventArgs e)
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
                if (!(e.Item is GridEditFormInsertItem))
                    GridEditableItem item = e.Item as GridEditableItem;
                    GridEditManager manager = item.EditManager;
                    GridTextBoxColumnEditor editor = manager.GetColumnEditor("ID") as GridTextBoxColumnEditor;
                    editor.TextBoxControl.Enabled = false;

        protected void gv1_NeedDataSource(object sender, Web.UI.GridNeedDataSourceEventArgs e)

while execution it does nothing,only grid is displayed without any of the CRUD operation
Plz Help,

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 01 Oct 2012, 06:49 AM

Most probably the problem comes from the fact that you are binding RadGrid with EntityDataSource just like in the demo application, but in the same time you are calling DataBind method of RadGrid. As this help article says you should not call anywhere in your code the DataBind method of RadGrid.

Try to remove all the code from the Page_Load method, remove the BindGrid method and the NeedDataSource event, you do not need these code fragments, when you are binding with EntityDataSource.

the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question