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

RadGrid - Manual CRUD

2 Answers 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sasha
Top achievements
Rank 1
Sasha asked on 08 Sep 2014, 08:08 PM
Trying to get my Radgrid to perform updates of records but have not been able to. I have been following this article(http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/manual-crud-operations/defaultcs.aspx?#qsf-demo-source) but because I am using content placeholders etc. can't follow it exactly. Below is my code, any suggestions on how to get the update to work would be appreciated. When I run the page, it just displays the data in the grid, the pencil icon does not show up to update. Any ideas?

Attached is the design and code behind.

Code Behind
01.using System;
02.using System.Collections.Generic;
03.using System.Linq;
04.using System.Web;
05.using System.Web.UI;
06.using System.Web.UI.WebControls;
07.using Business.Admin;
08.using Telerik.Web.UI;
09. 
10.namespace XX.Admin
11.{
12.    public partial class AdminLookUp : System.Web.UI.Page
13.    {
14.        protected void Page_Load(object sender, EventArgs e)
15.        {
16.            //if (!IsPostBack)
17.            //{
18.            //    LoadData();
19.            //}
20.        }
21. 
22.        public void LoadData(object source, GridNeedDataSourceEventArgs e)
23.        {
24.            //load data for lookup grid
25.            AdminLookUpBO lookUp = new AdminLookUpBO();
26.            List<AdminLookUpVO> getLookUpData;
27. 
28.            getLookUpData = lookUp.GetLookUpData();
29. 
30.            AdminLookUpGrid.DataSource = getLookUpData;
31.        }
32. 
33.        protected void goBackButton_Click(object sender, EventArgs e)
34.        {
35.            Response.Redirect("~/Admin/AdminMain.aspx");
36.        }
37. 
38. 
39.        protected void UpdateData(object source, GridCommandEventArgs e)
40.        {
41.               //update data for lookup grid
42.            AdminLookUpBO lookup = new AdminLookUpBO();
43. 
44.            var editableItem = ((GridEditableItem)e.Item);
45.            int lookUpId = (int)editableItem.GetDataKeyValue("ID");
46.            bool result = false;
47. 
48.            result = lookup.UpdateData(lookUpId, editableItem);
49.           
50.        }
51. 
52. 
53.    }
54.}


001.<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AdminLookUp.aspx.cs" Inherits="XX.Admin.AdminLookUp" %>
002.<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
003.<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
004.        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
005.        <script type="text/javascript">
006.            function rowDblClick(sender, eventArgs) {
007.                sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
008.            }
009.        </script>
010.    </telerik:RadCodeBlock>
011.</asp:Content>
012.<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
013.       <div class="centeredContent">
014.        <div class="centeredTable">
015.            <table align="center" width="900">
016.                <tr>
017.                    <td>
018.                        <p align="center" class="mediumHeader">
019.                            <asp:Label ID="adminLookupLabel"
020.                                runat="server"
021.                                Text='<%$ Resources:Resource, AdminLookUpTitle %>'
022.                                CssClass="mediumHeader" />
023.                        </p>
024.                    </td>
025.                </tr>
026.                <tr>
027.                    <td>
028.                        <asp:Label ID="errorMessageLabel" runat="server" CssClass="ErrorLabelTable" Text="" Visible="false" />
029.                    </td>
030.                </tr>
031.            </table>
032. 
033.            <table align="center" width="900">
034.                <tr>
035.                    <td>
036.                        <div style="width: 900px; height: auto">
037. 
038.                            <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
039.                                <AjaxSettings>
040.                                    <telerik:AjaxSetting AjaxControlID="AdminLookUpGrid">
041.                                        <UpdatedControls>
042.                                            <telerik:AjaxUpdatedControl ControlID="AdminLookUpGrid" />
043.                                        </UpdatedControls>
044.                                    </telerik:AjaxSetting>
045.                                </AjaxSettings>
046.                            </telerik:RadAjaxManager>
047.                            <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" />
048. 
049.                            <telerik:RadGrid ID="AdminLookUpGrid" runat="server"
050.                                AllowPaging="True" Skin="Windows7"
051.                                AllowAutomaticUpdates="True"
052.                                AutoGenerateColumns="False"
053.                                CellSpacing="0"
054.                                Height="300px"
055.                                GridLines="None"
056.                                OnNeedDataSource="LoadData" OnUpdateCommand="UpdateData"
057.                                AllowMultiRowSelection="True" Width="900px">
058.                                <ClientSettings>
059.                                    <Selecting AllowRowSelect="True" />
060.                                </ClientSettings>
061.                                <MasterTableView DataKeyNames="ID, User_ID, First_Name, Last_Name, Employee_Number, Role_Function, Is_Active"
062.                                                 ShowHeadersWhenNoRecords="True">
063.                                    <Columns>
064.                                        <telerik:GridBoundColumn DataField="ID" Visible="false">    
065.                                        </telerik:GridBoundColumn>
066.                                        <telerik:GridBoundColumn DataField="User_ID"
067.                                            HeaderText='<%$ Resources:Resource, AdminLookUp_UserID %>'
068.                                            UniqueName="User_ID">
069.                                            <HeaderStyle Width="250px" />
070.                                        </telerik:GridBoundColumn>
071.                                        <telerik:GridBoundColumn DataField="First_Name"
072.                                            HeaderText='<%$ Resources:Resource, AdminLookUp_FirstName %>'
073.                                            UniqueName="First_Name">
074.                                            <HeaderStyle Width="100px" />
075.                                        </telerik:GridBoundColumn>
076.                                        <telerik:GridBoundColumn DataField="Last_Name"
077.                                            HeaderText='<%$ Resources:Resource, AdminLookUp_LastName %>'
078.                                            UniqueName="Last_Name">
079.                                            <HeaderStyle Width="100px" />
080.                                        </telerik:GridBoundColumn>
081.                                        <telerik:GridBoundColumn DataField="Employee_Number"
082.                                            HeaderText='<%$ Resources:Resource, AdminLookUp_EmployeeNumber %>'
083.                                            UniqueName="Employee_Number">
084.                                            <HeaderStyle Width="100px" />
085.                                        </telerik:GridBoundColumn>
086.                                        <telerik:GridBoundColumn DataField="Role_Function"
087.                                            HeaderText='<%$ Resources:Resource, AdminLookUp_RoleFunction %>'
088.                                            UniqueName="Role_Function">
089.                                            <HeaderStyle Width="100px" />
090.                                        </telerik:GridBoundColumn>
091.                                        <telerik:GridBoundColumn DataField="Is_Active"
092.                                            HeaderText='<%$ Resources:Resource, AdminLookUp_IsActive %>'
093.                                            UniqueName="Is_Active">
094.                                            <HeaderStyle Width="100px" />
095.                                        </telerik:GridBoundColumn>
096.                                    </Columns>
097.                                    <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
098.                                </MasterTableView>
099.                                <PagerStyle PageSizeControlType="None"></PagerStyle>
100.                                <FilterMenu EnableImageSprites="False"></FilterMenu>
101.                            </telerik:RadGrid>
102. 
103. 
104.                        </div>
105.                    </td>
106.                </tr>
107.                <tr>
108.                     
109.                    <td align="right">
110.                        <asp:Button ID="saveButton" runat="server" Text="Save" />
111.                        <asp:Button ID="cancelButton" runat="server" Text="Cancel" />
112.                        <asp:Button ID="goBackButton" runat="server" Text="GoBack" OnClick="goBackButton_Click" />
113.                    </td>
114.                </tr>
115.            </table>
116.        </div>
117.   </div>
118.</asp:Content>

2 Answers, 1 is accepted

Sort by
0
Accepted
Radoslav
Telerik team
answered on 10 Sep 2014, 08:53 AM
Hello Sasha,

From the pasted markup code I saw that you do not have GridEditCommandColumn. Can you please add such column and let me know if the edit button is shown:
...
<telerik:GridEditCommandColumn ButtonType="ImageButton" />
...

Looking forward for your reply.

Regards,
Radoslav
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Sasha
Top achievements
Rank 1
answered on 15 Sep 2014, 11:39 PM
Thanks
Tags
Grid
Asked by
Sasha
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Sasha
Top achievements
Rank 1
Share this question
or