How to connect SharePoint list to RadGrid

3 posts, 0 answers
  1. Alex
    Alex avatar
    23 posts
    Member since:
    Dec 2012

    Posted 20 Dec 2012 Link to this post

    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>

    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;

    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!
  2. Pavlina
    Pavlina avatar
    6187 posts

    Posted 24 Dec 2012 Link to this post

    Hi Alex,

    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.

    More information on our controls for SharePoint 2010 you can find at the following SP 2010 site of ours:

    Kind regards,
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. Pistle
    Pistle avatar
    20 posts
    Member since:
    Sep 2020

    Posted 01 Oct Link to this post

    You  need a DataSource control to get the design-time support for RadGrid's columns.
    Otherwise, the grid does not have a way to know what data will be coming into and in what structure.
    The other option is to statically design the columns and all the other properties and then pass the data in the NeedDataSource event, but then you have to know what column fields the data contains.

Back to Top