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>
<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", "");
}
}
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>
<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", "");
}
}