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

Coding Error in RadGrid

5 Answers 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yong
Top achievements
Rank 2
Yong asked on 21 Aug 2008, 10:11 AM
Hi,

My problem

1) How do i update, insert and delete from my radgrid using custom edit template?

I have provided the following coding, any help or example is much appreciated.

The following coding is using the 3 tier model and is a web user control to be used in share point.

thank you

UI


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CLManagement.ascx.cs" Inherits="CLManagement" %>
<%@ Register Assembly="Telerik.Web.UI, Version=2008.2.723.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4"
    Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Assembly="DemoProject.BLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4d6fe3d9b7315a53"
    Namespace="DemoProject.BLL" TagPrefix="BLL" %>   
<%@ Register Assembly="DemoProject.DAL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=49aaa8eb85eb2046"
    Namespace="DemoProject.DAL" TagPrefix="DAL" %>

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnablePageHeadUpdate="False">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="CLRadTabStrip">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="CLRadTabStrip" />
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>

<telerik:RadAjaxPanel ID="CLRadAjaxPanel" runat="server" Height="200px" Width="100%">

<telerik:RadTabStrip ID="CLRadTabStrip" runat="server" SelectedIndex="3" Skin="Telerik" Width="100%" OnTabClick="CLRadTabStrip_TabClick">
    <Tabs>
        <telerik:RadTab runat="server" Text="State" Value="CLState">
        </telerik:RadTab>
        <telerik:RadTab runat="server" Text="Race" Value="CLRace">
        </telerik:RadTab>
        <telerik:RadTab runat="server" Text="Citizen" Value="CLCitizen">
        </telerik:RadTab>
        <telerik:RadTab runat="server" Text="Religion" Value="CLReligion" Selected="True">
        </telerik:RadTab>
        <telerik:RadTab runat="server" Text="Bank" Value="CLBank">
        </telerik:RadTab>
        <telerik:RadTab runat="server" Text="Product Type" Value="CLProductType">
        </telerik:RadTab>
    </Tabs>
</telerik:RadTabStrip>
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellPadding="0" Font-Bold="False" Font-Italic="False" Font-Names="Arial" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" GridLines="None" ShowFooter="True" ShowStatusBar="True" Skin="Telerik" Width="100%" OnInsertCommand="Radgrid1_InsertCommand" OnUpdateCommand="Radgrid1_UpdateCommand">
        <FooterStyle Font-Bold="False" Font-Italic="False" Font-Names="Arial" Font-Overline="False"
            Font-Strikeout="False" Font-Underline="False" Wrap="True" />
        <AlternatingItemStyle Font-Bold="False" Font-Italic="False" Font-Names="Arial" Font-Overline="False"
            Font-Strikeout="False" Font-Underline="False" Wrap="True" />
        <ItemStyle Font-Bold="False" Font-Italic="False" Font-Names="Arial" Font-Overline="False"
            Font-Strikeout="False" Font-Underline="False" Wrap="True" />
        <PagerStyle Font-Bold="False" Font-Italic="False" Font-Names="Arial" Font-Overline="False"
            Font-Strikeout="False" Font-Underline="False" Wrap="True" />
        <MasterTableView CommandItemDisplay="Bottom" GridLines="None">
            <RowIndicatorColumn>
                <HeaderStyle Width="20px" />
            </RowIndicatorColumn>
            <ExpandCollapseColumn>
                <HeaderStyle Width="20px" />
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridBoundColumn ColumnEditorID="Code" HeaderText="Code" UniqueName="Code">
                    <HeaderStyle Font-Bold="False" Font-Italic="False" Font-Names="Arial" Font-Overline="False"
                        Font-Strikeout="False" Font-Underline="False" Wrap="True" />
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn ColumnEditorID="Description" HeaderText="Description" UniqueName="Description">
                    <HeaderStyle Font-Bold="False" Font-Italic="False" Font-Names="Arial" Font-Overline="False"
                        Font-Strikeout="False" Font-Underline="False" Wrap="True" />
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn ColumnEditorID="Status" HeaderText="Status" UniqueName="Status">
                    <HeaderStyle Font-Bold="False" Font-Italic="False" Font-Names="Arial" Font-Overline="False"
                        Font-Strikeout="False" Font-Underline="False" Wrap="True" />
                </telerik:GridBoundColumn>
                <telerik:GridEditCommandColumn HeaderText="Edit">
                </telerik:GridEditCommandColumn>
                <telerik:GridButtonColumn HeaderText="Delete" Text="Delete" UniqueName="Delete">
                </telerik:GridButtonColumn>
            </Columns>
            <EditFormSettings EditFormType="Template">
                <EditColumn UniqueName="EditCommandColumn1">
                </EditColumn>
 <FormTemplate>
   <table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0">
   
    <tr><td><table id="Table3" cellspacing="1" cellpadding="1" width="250" border="0" class="module">
    <tr><td>Code:</td>
    <td><telerik:RadTextBox ID="tbRadCode" runat="server" Text='<%# Bind( "Code" ) %>'></telerik:RadTextBox></td></tr>
    <tr><td>Description:</td>
    <td><telerik:RadTextBox ID="tbRadDesc" runat="server" Text='<%# Bind( "Description") %>' TabIndex="1"></telerik:RadTextBox></td></tr>
    <tr><td>Status:</td>
    <td><telerik:RadTextBox ID="tbRadStatus" runat="server" Text='<%# Bind( "Status") %>' TabIndex="2"></telerik:RadTextBox></td></tr>
    </table></td></tr>
   
    <tr><td align="right" colspan="1">
    <asp:Button ID="btSubmit" runat="server" Font-Bold="True" Text="Submit" commandname="Radgrid1_UpdateCommand"></asp:Button>&nbsp;
    <asp:Button ID="btCancel" runat="server" Text="Cancel" Font-Bold="True" commandname="Cancel"></asp:Button></td>
     </tr></table>
                    </FormTemplate>
            </EditFormSettings>
        </MasterTableView>
        <SelectedItemStyle Font-Bold="False" Font-Italic="False" Font-Names="Arial" Font-Overline="False"
            Font-Strikeout="False" Font-Underline="False" Wrap="True" />
        <HeaderStyle Font-Bold="False" Font-Italic="False" Font-Names="Arial" Font-Overline="False"
            Font-Strikeout="False" Font-Underline="False" Wrap="True" />
        <GroupHeaderItemStyle Font-Bold="False" Font-Italic="False" Font-Names="Arial" Font-Overline="False"
            Font-Strikeout="False" Font-Underline="False" Wrap="True" />
        <FilterMenu EnableTheming="True" Skin="Telerik">
            <CollapseAnimation Duration="200" Type="OutQuint" />
        </FilterMenu>
        <EditItemStyle Font-Bold="False" Font-Italic="False" Font-Names="Arial" Font-Overline="False"
            Font-Strikeout="False" Font-Underline="False" Wrap="True" />
    </telerik:RadGrid></telerik:RadAjaxPanel>  


Code Behind
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using DemoProject.BLL;

[System.ComponentModel.Description("CLManagement")]

public partial class CLManagement : System.Web.UI.UserControl
{
    BLLCodeList _bllCL = new BLLCodeList();

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void CLRadTabStrip_TabClick(object sender, Telerik.Web.UI.RadTabStripEventArgs e)
    {
        //DataTable dt = ;dt.DefaultView;
        RadGrid1.DataSource = _bllCL.searchCLTable(CLRadTabStrip.SelectedTab.Value.ToString(), "", "");
        RadGrid1.MasterTableView.DataKeyNames = new string[] { "Id" };
        RadGrid1.DataBind();
    }

    protected void Radgrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;
        string Code = (insertedItem["Code"].Controls[0] as TextBox).Text;
        string Description = (insertedItem["Description"].Controls[0] as TextBox).Text;
        _bllCL.insertCLTable(CLRadTabStrip.SelectedTab.Value.ToString(), "Code", "Description", HttpContext.Current.User.Identity.Name);
    }

    protected void Radgrid1_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        string Description = (editedItem.FindControl("tbRadDesc") as TextBox).Text;
        _bllCL.updateCLTable(CLRadTabStrip.SelectedTab.Value.ToString(), "Description", "");

    }
}

5 Answers, 1 is accepted

Sort by
0
Yong
Top achievements
Rank 2
answered on 22 Aug 2008, 06:55 AM
Anyone?
0
Kiara
Top achievements
Rank 1
answered on 22 Aug 2008, 02:29 PM
Yong, with FormTemplate custom edit form you need to use either NeedDataSource binding or data source control for grid item generator in order to edit/update/insert and delete grid records.

I used the code from these help article for my template edit form implementation and they worked just fine:

http://www.telerik.com/help/aspnet-ajax/grdupdatingvaluesusercontrolformtemplate.html
http://www.telerik.com/help/aspnet-ajax/grdinsertingvaluesusercontrolformtemplate.html
http://www.telerik.com/help/aspnet-ajax/grdhowtodeletearecord.html

Hope these pointers are helpful to you.

Kiara
0
Yong
Top achievements
Rank 2
answered on 22 Aug 2008, 03:21 PM
Hi,

Thank you for your reply

but i still do not know how to apply

http://www.telerik.com/demos/aspnet/prometheus/Grid/Examples/DataEditing/TemplateFormUpdate/DefaultCS.aspx

in my current situation

do you mind doing a small sample based on my above code for reference?

as i have been trying for the past few days to do and still unable.

So far i am left with the following functions : add new record and edit record

thank you
0
Kiara
Top achievements
Rank 1
answered on 25 Aug 2008, 08:36 AM
Have you reviewed the doc links from my previous response? They hold the update/insert/delete coding you need when you want manual editing for the grid with form template edit form. Tranform the code for your particular form template editors (ids and so on) and you should be done.

Kiara
0
Princy
Top achievements
Rank 2
answered on 02 Sep 2008, 11:05 AM
Hi Yong,

I have submitted a code library on the same
Manual Insert/Update/Delete using FormTemplate and Sql backend

Let me know how it goes.


Thanks,
Princy
Tags
Grid
Asked by
Yong
Top achievements
Rank 2
Answers by
Yong
Top achievements
Rank 2
Kiara
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or