Unable to Edit, Update and Delete from the RadGrid

3 posts, 0 answers
  1. rinu
    rinu avatar
    15 posts
    Member since:
    Jun 2010

    Posted 16 Jul 2015 Link to this post

     

    Dear All,

     i followed the link http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/automatic-crud-operations/defaultcs.aspx and was able to see the data data in the RadGrid. But i was unable to edit or delete and when i tried to insert a row i wasn't able to see the text box where you can enter the data. i can only see a tick and a cross button . when i click on the tick button an empty row will be added to the table.

     .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
            }
        }
    }

    please advice

    Regards

    Kannan

  2. Kostadin
    Admin
    Kostadin avatar
    1733 posts

    Posted 21 Jul 2015 Link to this post

    Hello Kannan,

    This behavior is pretty strange and based on the provided information will be hard to pinpoint the reason for that behavior. Nevertheless I noticed that you have AJAX enabled on your page. Could you please disable the AJAX and let me know whether a server side exception is not thrown?

    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
  3. rinu
    rinu avatar
    15 posts
    Member since:
    Jun 2010

    Posted 21 Jul 2015 in reply to Kostadin Link to this post

    The problem was with the SQLDataSource control
Back to Top