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

Rad grid not doing CRUD(Means doing nothing)

5 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Swapnil
Top achievements
Rank 1
Swapnil asked on 26 Sep 2012, 07:10 AM
I am trying to d CRUD with Entity Framework Automatically using the article:
http://demos.telerik.com/aspnet-ajax/grid/examples/automaticoperations/efdatabinding/defaultcs.aspx
but it does nothing operation just showing grid,
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" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<head id="Head1" runat="server">
    <style type="text/css">
        .MyImageButton
        {
            cursor: hand;
        }
        .EditFormHeader td
        {
            font-size: 14px;
            padding: 4px !important;
            color: #0066cc;
        }
    </style>
</head>
<body class="BODY" style="background-color: Black">
    <form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <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" />
            <ClientSettings>
                <Selecting CellSelectionMode="None"></Selecting>
            </ClientSettings>
            <MasterTableView DataSourceID="EntityDataSource1" AutoGenerateColumns="False" DataKeyNames="ID"
                CommandItemDisplay="Top">
                <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
                <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                </RowIndicatorColumn>
                <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                </ExpandCollapseColumn>
                <Columns>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                    </telerik:GridEditCommandColumn>
                    <telerik:GridBoundColumn DataField="ID" HeaderText="ID" SortExpression="ID" UniqueName="ID"
                         MaxLength="5">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name"
                        UniqueName="Name">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Address" HeaderText="Address" SortExpression="Address"
                        UniqueName="Address">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="DeptID" HeaderText="DeptID" SortExpression="DeptID"
                        UniqueName="DeptID">
                    </telerik:GridBoundColumn>
                    <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton" />
                </Columns>
                <EditFormSettings>
                    <EditColumn ButtonType="ImageButton" />
                </EditFormSettings>
            </MasterTableView>
            <FilterMenu EnableImageSprites="False">
            </FilterMenu>
        </telerik:RadGrid>
        <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=Entity"
            DefaultContainerName="Entity" EnableDelete="True" EnableFlattening="False" EnableInsert="True"
            EnableUpdate="True" EntitySetName="EMPLOYEEs" EntityTypeFilter="EMPLOYEE">
        </asp:EntityDataSource>
    </div>
    </form>
</body>
</html>
 
Code 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;
                BindGrid();
        }
 
        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)
        {
            BindGrid();
        }
    }
}

plz help
thanks.

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Sep 2012, 07:32 AM
Hi Swapnil,

Try binding the RadGrid Declaratively and remove the NeedDataSource event and binding the RadGrid in PageLoad, if you need automatic CRUD operation. The automatic data source operations only work when binding the grid to a declarative data source using the DataSourceID property of the grid. You must configure the data source so that it supports the automatic operations.

Thanks,
Shinu.
0
Swapnil
Top achievements
Rank 1
answered on 26 Sep 2012, 07:47 AM
I tried like this ,but it also not working
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;
                //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;
            RadGrid1.DataSourceID = null;
            RadGrid1.DataBind();
        }
 
        public void BindGrid()
        {
                 
        }
 
        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)
        {
            //BindGrid();
        }
    }
}
if this not correct way then how can i do this?
Thanks.
0
Shinu
Top achievements
Rank 2
answered on 26 Sep 2012, 08:35 AM
Hi Swapnil,

No need for binding the RadGrid in PageLoad or any code behind methods. You have already set the property 'DataSourceID' of RadGrid to an EntityDataSource ie 'EntityDataSource1' in ASPX and bound the RadGrid Declaratively.

Thanks,
Shinu.
0
Swapnil
Top achievements
Rank 1
answered on 26 Sep 2012, 09:01 AM
If there is no need to bind rad grid on code page then how will be the query(which retrives all data in grid at page load) executes,
var query5 = from employee in ent.EMPLOYEEs
                    select new
                     {
                           ID = employee.ID,
                           NAME = employee.NAME
                           ADDRESS = employee.ADDRESS,
                           DEPTID = employee.DEPTID
                            };

Thanks
0
Shinu
Top achievements
Rank 2
answered on 27 Sep 2012, 04:28 AM
Hi,

You can populate the RadGrid with desired data fields using declarative method also through which you can perform automatic operations.
aspx:
<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" />
            <ClientSettings>
                <Selecting CellSelectionMode="None"></Selecting>
            </ClientSettings>
            <MasterTableView DataSourceID="EntityDataSource1" AutoGenerateColumns="False" DataKeyNames="ID"
                CommandItemDisplay="Top">
                <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
                <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                </RowIndicatorColumn>
                <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                </ExpandCollapseColumn>
                <Columns>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                    </telerik:GridEditCommandColumn>
                    <telerik:GridBoundColumn DataField="ID" HeaderText="ID" SortExpression="ID" UniqueName="ID"
                         MaxLength="5">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name"
                        UniqueName="Name">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Address" HeaderText="Address" SortExpression="Address"
                        UniqueName="Address">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="DeptID" HeaderText="DeptID" SortExpression="DeptID"
                        UniqueName="DeptID">
                    </telerik:GridBoundColumn>
                    <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton" />
                </Columns>
                <EditFormSettings>
                    <EditColumn ButtonType="ImageButton" />
                </EditFormSettings>
            </MasterTableView>
            <FilterMenu EnableImageSprites="False">
            </FilterMenu>
        </telerik:RadGrid>
        <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=Entity"
            DefaultContainerName="Entity" EnableDelete="True" EnableFlattening="False" EnableInsert="True"
            EnableUpdate="True" EntitySetName="EMPLOYEEs" EntityTypeFilter="EMPLOYEE">
        </asp:EntityDataSource>

C#:
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;
                }
            }
        }

Thanks,
Shinu.
Tags
Grid
Asked by
Swapnil
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Swapnil
Top achievements
Rank 1
Share this question
or