This is a migrated thread and some comments may be shown as answers.

How to connect SharePoint list to RadGrid

2 Answers 196 Views
WebParts for SharePoint
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 20 Dec 2012, 06:52 PM
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>

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

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 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 24 Dec 2012, 02:41 PM
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:
http://sharepoint.telerik.com

Kind regards,
Pavlina
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.
0
Pistle
Top achievements
Rank 1
Veteran
answered on 01 Oct 2020, 12:42 PM
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.

Regards
Tags
WebParts for SharePoint
Asked by
Alex
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Pistle
Top achievements
Rank 1
Veteran
Share this question
or