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!
Microsoft SharePointWeb ComponentsC#

Avatar of undefined
Last Comment
vpit

8/22/2022 - Mon
SOLUTION
Uttam (Kukdai) Dhakal

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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
vpit

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck