Link to home
Start Free TrialLog in
Avatar of vpit
vpit

asked on

How to connect SharePoint 2010 list to Telerik RadGrid

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

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;
                        GridView1.DataBind();
                         
                    }
                }
            }
        }

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!
SOLUTION
Avatar of Uttam (Kukdai) Dhakal
Uttam (Kukdai) Dhakal
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vpit
vpit

ASKER

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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vpit

ASKER

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.