Contents
Licensing
Installation and deployment
RadControls for ASP.NET AJAX Fundamentals
RadControls
RadAjax
RadAsyncUpload
RadBarcode
RadButton
RadCalendar
RadCaptcha
RadChart
RadColorPicker
RadComboBox
RadDataPager
RadDock
RadEditor
RadFileExplorer
RadFilter
RadFormDecorator
RadGrid
Getting Started
Design Time
ASP.NET 3.5 Features
Columns
Rows
Defining Structure
Data Binding
Sorting
Paging
Scrolling
Grouping
Filtering
Selecting
Insert/Update/Delete
Hierarchical Grid Types and Load Modes
Exporting
Layout
Visible/Enabled Conventions
Ajaxified RadGrid
Inheritance
Control Lifecycle
Performance
Appearance and Styling
Accessibility and Internationalization
How To
Server-Side Programming
Client-Side Programming
Application Scenarios
Troubleshooting
RadHtmlChart
RadImageEditor
RadInput
RadListBox
RadListView
RadMenu
RadNotification
RadODataDataSource
RadOrgChart
RadPanelBar
RadRating
RadRibbonBar
RadRotator
RadScheduler
RadScriptManager
RadSitemap
RadSlider
RadSocialShare
RadSpell
RadSplitter
RadStylesheetManager
RadTabStrip
RadTagCloud
RadToolBar
RadToolTip
RadTreeList
RadTreeView
RadUpload
RadWindow
RadXmlHttpPanel
Visual Studio Extensions
Integrating RadControls in ASPNET MVC
Integrating RadControls in DNN
Integrating RadControls in Mono
Integrating RadControls in SharePoint
API Reference
For More Help
|
|
        RadControls for ASP.NET AJAX
You can load the structure of a RadGrid control from a file
containing its XML representation. This approach is useful when you want to
load grid instances with equal predefined settings on different pages of your
web site.
The following steps describe how to import the structure of a grid:
Create an XSL file that contains the grid structure you want to import
and a dummy XML file for receiving the grid structure.
On the ASPX file for the Web page, add a PlaceHolder
control to receive the grid, plus any other elements you want (such as data
source controls).
In the Page_Init event handler of your Web page
Load an XPathDocument with the dummy XML file
and an XslCompiledTransform object with the XSL
file you created.
Create a StringWriter.
With the XslCompiledTransform object, use the
StringWriter to transform the XSL definition to
the XML file. This loads the transformed XML file into the
StringWriter.
Create a StringBuilder object, and initialize
it with the "<%@ Register >" directive for the Telerik.Web.UI
assembly.
Load the contents of the StringWriter (the
grid structure) into your StringBuilder
object.
Using the StringBuilder, remove theXML file
header and xmlns string.
Call Page.ParseControl, passing in the
contents of the StringBuilder, to create an
instance of the grid based on the structure that the
StringBuilder contains.
Add the grid instance to the PlaceHolder
control in the ASPX file for the Web page.
Note |
|---|
The grid should be
loaded and added to the Web page in the Page_Init event
handler.
|
CopyXML <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:telerik="remove">
<xsl:template match="/">
<div>
<telerik:RadGrid
ID="RadGrid1" runat="server"
DataSourceID="SqlDataSource1";
Width="95%"
AllowFilteringByColumn="True"
AllowSorting="True"
PageSize="15"
ShowFooter="True"
ShowGroupPanel="True"
AllowPaging="True"
AllowMultiRowSelection="True">
<HeaderStyle Width="150px" />
<ClientSettings
ReorderColumnsOnClient="True"
AllowDragToGroup="True"
AllowColumnsReorder="True">
<Scrolling
AllowScroll="True"
UseStaticHeaders="True">
</Scrolling>
<Resizing
AllowRowResize="True"
AllowColumnResize="True">
</Resizing>
<Selecting AllowRowSelect="True" />
</ClientSettings>
</telerik:RadGrid>
</div>
</xsl:template>
</xsl:stylesheet> CopyXML <?xml version="1.0" encoding="utf-8" ?>
<root>
<foo/>
</root>In the code-behind: CopyC# public void Page_Init(object sender, EventArgs e)
{
XPathDocument MyXPathDocument = new XPathDocument(Server.MapPath("XMLFile.xml"));
XslCompiledTransform MyXslTransform = new XslCompiledTransform();
MyXslTransform.Load(Server.MapPath("XSLTFile.xsl"));
StringWriter MyStringWriter = new StringWriter();
MyXslTransform.Transform(MyXPathDocument, null, MyStringWriter);
StringBuilder MyStringBuilder = new StringBuilder();
MyStringBuilder.Append(@"<%@ Register Assembly=""Telerik.Web.UI"" Namespace=""Telerik.Web.UI"" TagPrefix=""telerik"" %>");
MyStringBuilder.Append(MyStringWriter.ToString());
MyStringBuilder = MyStringBuilder.Replace("xmlns:telerik=\"remove\"", "");
MyStringBuilder = MyStringBuilder.Replace(@"<?xml version=""1.0"" encoding=""utf-16""?>", "");
Control ctrl = Page.ParseControl(MyStringBuilder.ToString());
PlaceHolder1.Controls.Add(ctrl);
} CopyVB.NET
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim MyXPathDocument As XPathDocument = New XPathDocument(Server.MapPath("~/App_Data/XMLFile.xml"))
Dim MyXslTransform As XslCompiledTransform = New XslCompiledTransform()
MyXslTransform.Load(Server.MapPath("~/App_Data/XSLTFile.xsl"))
Dim MyStringWriter As StringWriter = New StringWriter()
MyXslTransform.Transform(MyXPathDocument, Nothing, MyStringWriter)
Dim MyStringBuilder As StringBuilder = New StringBuilder()
MyStringBuilder.Append("<%@ Register Assembly=""Telerik.Web.UI"" Namespace=""Telerik.Web.UI"" TagPrefix=""telerik"" %>")
MyStringBuilder.Append(MyStringWriter.ToString())
MyStringBuilder = MyStringBuilder.Replace("xmlns:telerik=""remove""", "")
MyStringBuilder = MyStringBuilder.Replace("<?xml version=""1.0"" encoding=""utf-16""?>", "")
Dim ctrl As Control = Page.ParseControl(MyStringBuilder.ToString())
PlaceHolder1.Controls.Add(ctrl)
End Sub
For a live example that shows this technique in practice, see Programmatic Creation from XML.
|