Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
select

Grid / Editing XML Using XmlDataSource

Add new recordRefresh
 CompanyNameContactName 
EditvvvvvvDelete

  • You can use XmlDataSource control and Telerik RadGrid to generate its content from XML and perform data editing operations. Note that automatic update, insert, and delete operations that work with other data source controls (AccessDataSource/SqlDataSource/ObjectDatSource) will not work in this case. You need to write custom code to modify data in the xml source.

    The following list outlines some restrictions on editing XML data using XmlDataSource control:

    • The XML data must be loaded from an XML file specified with the DataFile property, and not from xml string specified in the Data property.
    • No XSLT transformation can be specified in the Transform or TransformFile properties.
    • The Save method does not handle concurrent save operations on unique requests. If more than one user is editing an XML file using the XmlDataSource control, there is no guarantee that all users are operating with the same data and that one user will not overwrite changes from another user. It is also possible for a Save operation to fail because another user is writing to the XML file and has an exclusive lock on the file.

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="VB" CodeFile="DefaultVB.aspx.vb" Inherits="Grid.Examples.DataEditing.XmlDataSourse.DefaultVB" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="telerik" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="sds" Namespace="Telerik.Web.SessionDS" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <telerik:HeadTag runat="server" ID="Headtag2"></telerik:HeadTag>
        <!-- custom head section -->
        <!-- end of custom head section -->
    </head>
    <body class="BODY">
        <form id="form1" runat="server">
            <div>
                <telerik:Header runat="server" ID="Header1" NavigationLanguage="VB"></telerik:Header>
              <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
                <!-- content start -->
                <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

                    <script type="text/javascript">
                function RowDblClick(sender, eventArgs)
                {
                  sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
                }
                    </script>

                </telerik:RadCodeBlock>
                <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                    <AjaxSettings>
                        <telerik:AjaxSetting AjaxControlID="RadGrid1">
                            <UpdatedControls>
                                <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                                <telerik:AjaxUpdatedControl ControlID="divMsg" />
                            </UpdatedControls>
                        </telerik:AjaxSetting>
                    </AjaxSettings>
                </telerik:RadAjaxManager>
                <div id="divMsg" runat="server" style="float: left;">
                    <asp:Label ID="lblMsg" runat="server" ForeColor="Red"></asp:Label>
                </div>
                <telerik:RadGrid ID="RadGrid1" runat="server" ShowStatusBar="true" DataSourceID="XmlDataSource1">
                    <MasterTableView AutoGenerateColumns="false" DataKeyNames="CustomerID" CommandItemDisplay="Top">
                        <Columns>
                            <telerik:GridEditCommandColumn>
                            </telerik:GridEditCommandColumn>
                            <telerik:GridBoundColumn UniqueName="CompanyName" DataField="CompanyName" HeaderText="CompanyName">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="ContactName" DataField="ContactName" HeaderText="ContactName">
                            </telerik:GridBoundColumn>
                            <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
                            </telerik:GridButtonColumn>
                        </Columns>
                    </MasterTableView>
                    <ClientSettings>
                        <ClientEvents OnRowDblClick="RowDblClick" />
                    </ClientSettings>
                </telerik:RadGrid>
                <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/Xml/XmlDataSourceExampleTemp.xml">
                </asp:XmlDataSource>
                <!-- content end -->
                <telerik:Footer runat="server" ID="Footer1"></telerik:Footer>
            </div>
        </form>
    </body>
    </html>

Get more than expected!

 
 

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451