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

Unable to Edit, Update and Delete from the RadGrid

1 Answer 30 Views
Grid
This is a migrated thread and some comments may be shown as answers.
rinu
Top achievements
Rank 1
rinu asked on 16 Jul 2015, 09:29 AM

i was following the link http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/automatic-crud-operations/defaultcs.aspx. and managed to see the records from the db but was unable to edit or delete them. and when i was trying to insert i wasnt able to see the textbox where you enter the records and only a tick box button and x button is available.

 

please see the code

 .aspx

 

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register assembly="System.Web.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" namespace="System.Web.UI.WebControls" tagprefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head id="Head1" runat="server">
    <title>Telerik ASP.NET Example</title>
    <link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <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:RadFormDecorator runat="server" DecorationZoneID="demo" EnableRoundedCorners="false" DecoratedControls="All" />
    <div id="demo" class="demo-container no-bg">
        <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="EntityDataSource1"
            AllowPaging="True" AllowAutomaticUpdates="True" AllowAutomaticInserts="True"
            AllowAutomaticDeletes="True" AllowSorting="True" OnItemCreated="RadGrid1_ItemCreated"
            OnItemInserted="RadGrid1_ItemInserted" OnPreRender="RadGrid1_PreRender" 
            OnInsertCommand="RadGrid1_InsertCommand" GroupPanelPosition="Top" 
            ResolvedRenderMode="Classic">
            <PagerStyle Mode="NextPrevAndNumeric" />
            <MasterTableView DataSourceID="EntityDataSource1" 
            AutoGenerateColumns="False" CommandItemDisplay="Top">
                <Columns>
                    
                    <telerik:GridBoundColumn DataField="Self_development" 
                        HeaderText="Self_development" SortExpression="Self_development"
                        UniqueName="Self_development" 
                        FilterControlAltText="Filter Self_development column" ReadOnly="True">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Technical_Development" 
                        HeaderText="Technical_Development" SortExpression="Technical_Development"
                        UniqueName="Technical_Development" 
                        FilterControlAltText="Filter Technical_Development column" ReadOnly="True">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Project_Management" 
                        HeaderText="Project_Management" SortExpression="Project_Management"
                        UniqueName="Project_Management" 
                        FilterControlAltText="Filter Project_Management column" ReadOnly="True">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Client_Relationship" 
                        HeaderText="Client_Relationship" SortExpression="Client_Relationship"
                        UniqueName="Client_Relationship" 
                        FilterControlAltText="Filter Client_Relationship column" ReadOnly="True">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Safety" HeaderText="Safety" SortExpression="Safety"
                        UniqueName="Safety" FilterControlAltText="Filter Safety column" 
                        ReadOnly="True">
                    </telerik:GridBoundColumn>
                    
                <telerik:GridBoundColumn DataField="Leadership_Development" 
                        FilterControlAltText="Filter Leadership_Development column" 
                        HeaderText="Leadership_Development" ReadOnly="True" 
                        SortExpression="Leadership_Development" UniqueName="Leadership_Development"></telerik:GridBoundColumn><telerik:GridBoundColumn 
                        DataField="ID" DataType="System.Int32" FilterControlAltText="Filter ID column" 
                        HeaderText="ID" ReadOnly="True" SortExpression="ID" UniqueName="ID"></telerik:GridBoundColumn></Columns>
                <EditFormSettings>
                    <EditColumn ButtonType="ImageButton" />
<EditColumn ButtonType="ImageButton"></EditColumn>
                </EditFormSettings>
            </MasterTableView>
        </telerik:RadGrid>
    </div>
    <%--<asp:EntityDataSource ID="EntityDataSourceCustomers" runat="server" ConnectionString="name=NorthwindReadWriteEntities"
        DefaultContainerName="NorthwindReadWriteEntities" EntitySetName="Customers" OrderBy="it.[ContactName]"
        EntityTypeFilter="Customer" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True">
    </asp:EntityDataSource>--%>
    <asp:EntityDataSource ID="EntityDataSource1" runat="server" 
        ConnectionString="name=LMSDBEntities3" DefaultContainerName="LMSDBEntities3" 
        EntitySetName="Course_mainPage" 
        OrderBy="it.[Self_development]"
        
        
        EnableDelete="True" EnableInsert="True" EnableUpdate="True" >
    </asp:EntityDataSource>
   <%-- Select="it.[Self_development], it.[Technical_Development], it.[Project_Management], it.[Client_Relationship], it.[Safety], it.[Leadership_Development], it.[ID]" --%>
    </form>
</body>
</html>​

 

c#

 

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

    }
    protected void RadGrid1_ItemCreated(object sender, Telerik.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 RadGrid1_ItemInserted(object source, GridInsertedEventArgs e)
    {
        if (e.Exception != null)
        {

            e.ExceptionHandled = true;
            SetMessage("Record cannot be inserted. Reason: " + e.Exception.Message);

        }
        else
        {
            SetMessage("New Record is inserted!");
        }
    }
    private void DisplayMessage(string text)
    {
        RadGrid1.Controls.Add(new LiteralControl(string.Format("<span style='color:red'>{0}</span>", text)));
    }

    private void SetMessage(string message)
    {
        gridMessage = message;
    }

    private string gridMessage = null;

    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(gridMessage))
        {
            DisplayMessage(gridMessage);
        }
    }

    protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
    {
        if (e.Item is GridEditableItem)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            //here editedItem.SavedOldValues will be the dictionary which holds the
            //predefined values

            //Prepare new dictionary object
            Hashtable newValues = new Hashtable();
            e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
            //the newValues instance is the new collection of key -> value pairs
            //with the updated ny the user data
        }
    }
}​

1 Answer, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 21 Jul 2015, 06:33 AM
Hi Kannan,

I already answered your other forum thread with the same requirement so I would appreciate if we continue our conversation there and close this one.

Regards,
Kostadin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
rinu
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Share this question
or