Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to connect SharePoint 2010 list to Telerik RadGrid

Posted on 2012-12-20
Medium Priority
Last Modified: 2013-02-19
I want to populate a RadGrid with SharePoint 2010 list data. I cannot figure out how this is accomplished.

Here is my ASPX page:
<SPWebControls:SPDataSource runat="server" ID="dsclientmatter" DataSourceMode="ListItem" UseInternalName="true">
      <asp:Parameter Name="WebUrl" DefaultValue="/configuration/" />
      <asp:Parameter Name="ListID" DefaultValue="4056449D-1884-4C79-AAAD-CD0ABEB2F854" />
      <asp:Parameter Name="ListItemID" DefaultValue="1" />
<telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" ShowStatusBar="true" PageSize="7" AllowPaging="True" DataSourceID="dsclientmatter" >
        <Selecting AllowRowSelect="True" />
<MasterTableView datasourceid="">
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
<FilterMenu EnableImageSprites="False"></FilterMenu>

Open in new window

Here is my code-behind:
protected void Page_Load(object sender, EventArgs e)
            SPSite site = new SPSite("http://abcdev");
            using (SPWeb web = site.OpenWeb())
                SPList clientlist = web.Lists.TryGetList("clientmatter");
                DataTable dt = new DataTable();
                SPQuery query = new SPQuery();
                query.ViewFields = "<Where><Eq><FieldRef Name='clientid'/><Value Type='Text'>12345</Value></Eq></Where>";
                SPListItemCollection items = clientlist.GetItems(query);
                if(items != null)
                    if(items.Count > 0)
                        dt = items.GetDataTable();                       
                        GridView1.DataSource = dt;

Open in new window

I don't know if this is the best way to start, but I do know something is wrong because I cant render any data. Plus, I don't understand why by RadGrid ID will not compile. I get an error stating "The name 'GridView1' does not exist in the current context". Why. That is the ID of my RadGrid.

My end goal is to create a RadGrid that I can filter by individual columns, such as: name, client#, topic, etc. I am not sure if the filtering allows for multiple entries, but I would like to be able to filter on more than one criteria. Also, wildcard searches are very important.

Thank you for the help!
Question by:vpit
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Assisted Solution

kukdai earned 2000 total points
ID: 38714835
First of all, create the columns that you want to display in the rad grid in the .aspx file.

in your code behind
write a function that loads the data into the rad grid.

create a data table and create the columns that are needed to store the values.

create a function that returns the data table.

inside that data table get the data from the list and assign each data to the columns that are created for the data table and return the data table.
now in the page load event
if it is not post back then load the function where you will assign the data source of the current rad grid to function that return the data table.

there is one function called needdatasource event in the rad grid.
if you click on the rad grid in the aspx file and check the event properties of the rad grid you can see needdatasource double click on that and write the code that will bind the data source with the data table.

i don't want to write the code here unless you need it there are bunch of examples about this i hope. you can also search in telerik forums they are of great help.

Author Comment

ID: 38724730
Telerik support replied via email and I wanted to post it here:

RadGrid, by itself, does not support binding to SPLists directly, neither can it handle an SPDataSource control.

However, there is a solution that you can employ in your project. Our controls for SharePoint go with an extension of RadGrid, called SPRadGrid. It is a standalone class that offers a built-in support for binding to SharePoint lists. What you need to do is to download the installer for the Telerik web parts for SharePoint 2010.

Go to Manager your producets -> Download Installer and Other Resources -> (Under RadControls for ASP.NET AJAX) Browser all product lines -> SharePoint 2007/2010 -> SharePoint 2010 Web Parts - Manual Installation. Within the zip file there is a wsp - make that with a .rar/.zip extension and extract the Telerik.Ajax.SharePoint.dll. In the dll, you will find the SPRadGrid class. Alternatively, you can download and run the installer of our extensions for SharePoint 2010 - it will install the web parts (you can use them or not as per your scenario) and deploy the dll to the GAC where you can safely reference it from.

I will look into this Telerik solution and the one offered by kukdai and post a reply soon.

Accepted Solution

vpit earned 0 total points
ID: 38890788
I found an answer how to connect to an external list posted by My implementation of his example is added below.

private List<Matters> matters = new List<Matters>();
        private IEnumerable<ListItem> returnedItems = null;

        public MainPage()
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);

        void MainPage_Loaded(object sender, RoutedEventArgs e)
            ClientContext context = ClientContext.Current;
            returnedItems = context.LoadQuery(
                context.Web.Lists.GetByTitle("myExternalListName").GetItems(new CamlQuery())
            context.ExecuteQueryAsync(succeededCallback, failedCallback);

        void succeededCallback(object sender, ClientRequestSucceededEventArgs e)
            this.Dispatcher.BeginInvoke(() =>
                    foreach (var item in returnedItems)
                        matters.Add(new Matters(item));
                    radGridView1.ItemsSource = matters;

        void failedCallback(object sender, ClientRequestFailedEventArgs e)
            MessageBox.Show(e.ErrorDetails.ToString(), "Error", MessageBoxButton.OK);

Open in new window

MainPage.xaml using Telerik RadGrid
<Grid x:Name="LayoutRoot" Background="White" Height="580">
        <controls:RadGridView Name="radGridView1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="12,12,0,0" CanUserSelect="True" CanUserFreezeColumns="False" AutoExpandGroups="False" AutoGenerateColumns="False" CanUserDeleteRows="False" AlternateRowBackground="CadetBlue" Width="600">
                <controls:GridViewDataColumn Header="Client Name" DataMemberBinding="{Binding ClientName}" />
                <controls:GridViewDataColumn Header="Client Num" DataMemberBinding="{Binding ClientNum}" />
                <controls:GridViewDataColumn Header="Billing Attorney" DataMemberBinding="{Binding BillingName}" />
        <telerik:RadDataPager PageSize="100" Width="600" HorizontalAlignment="Left" Source="{Binding Items, ElementName=GridView}"
								  DisplayMode="FirstLastPreviousNextNumeric, Text" Margin="0,552,0,0" />

Open in new window

Class file - _item.FieldValues are the database table column names
private ListItem _item;

        public myClassFileName(ListItem item) { _item = item; }
        public string ClientName { get { return _item.FieldValues["Client_Name"].ToString(); } }
        public string ClientNum { get { return _item.FieldValues["Client_Number"].ToString(); } }
        public string BillingName { get { return _item.FieldValues["Billing_Name"].ToString(); } }

Open in new window


Author Closing Comment

ID: 38904773
Kukdai's answer was a good series of steps which is why I gave him 500 points, but the details in the final solution were found and posted in my reply. While I gave the expert all 500 points for his valued input, I selected my reply as the "best answer" because it gave all the detailed steps.

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you will learn how to create a free basic website on Bitbucket, a git service provider. Polymer creates dynamic HTML components, which allow more flexibility than static HTML. This tutorial uses Ubuntu Linux but can also be done on W…
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question