Integrate Telerik RadGrid And SqlDataSource Using XsltDb ASP.NET
Published on 6/1/2010 by Anton Burtsev
All Articles / Live Demos / Common modules
Article shows how to use RadGrid and SqlDataSource to display a query in a professional gridview on a DotNetNuke page.
Live Demo for the article can be found here.
XsltDb is capable of instantiating ASP.NET controls. This is very useful since DotNetNuke includes a powerfull Telerik UI library. Here I create a list of modules installed on the current DotNetNuke web site using ASP.NET SqlDataSource object to query database and RadGrid control to display the data on the page.
The code is very simple:
<mdo:asp xmlns:asp="asp" xmlns:telerik="telerik">
<asp:SqlDataSource
id="dsModules"
runat="server"
ConnectionString="<%$ ConnectionStrings:SiteSqlServer %>"
SelectCommand="SELECT ModuleName, FriendlyName, Description FROM dnn_DesktopModules"
/>
<telerik:RadGrid
ID="RadGrid1"
DataSourceID="dsModules"
AllowPaging="True"
PageSize="10"
runat="server">
</telerik:RadGrid>
</mdo:asp>
Code sample for editable RadGrid can be found here:
http://xsltdb.codeplex.com/Thread/View.aspx?ThreadId=240550
View This Code Live
Attention! As we want to access the DNN database we must check Super Module option in the top right corner above the XSLT textarea.
First, we create a zone where ASP.NET controls resides - <mdo:asp>. This allows XsltDb engine effectively clear asp and teleriknamespaces from the resulting HTML. In this tag we must describe all prefixes that we use inside.
In the
SqlDataSource we reference a connection string specified in web.config. We also can provide an alternative connection string to access any database. Note that angular braces are replaced with < and > as we have to our keep code as valid XML.
After we created a SqlDataSource we can create a RadGrid object and reference our datasource.
This sample creates ASP.NET objects with their default settings. Actually we can use full set of capabilities of the objects including sorting and filtering data, skinning UI controls and all other features provided by Microsoft and Telerik.
Print Article