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

Bind SPList to RadGrid

3 Answers 132 Views
Sharepoint Integration
This is a migrated thread and some comments may be shown as answers.
Shiri
Top achievements
Rank 1
Shiri asked on 24 Jun 2009, 11:27 AM
Hello,

We have tried to bind SPList to the RadGrid using two strategies that we saw in the examples and forum.
1.To use the method SPList.GetDataTable() and to bind the dataTable to the RadGrid. The problem with this option that GetDataTable() contains only String and Int32 types, no Boolean and other types of SPField.
2. The second strategy was to bind SPListItemCollection of the list (we tryed to return spesific columns and all items).
The problem here is RadGrid does not display all columns that are in SPListItemCollection, particulary it does not display the columns that were added manually from sharepoint UI. We work on server side, we also tried autogenerate columns and custom generate, in both cases there is no results in RadGrid.

Can you please sent us some example of how to bind SPListItemCollection to RadGrid or any other way to bind SPList to RadGrid.

Thank you,
Shiri.

3 Answers, 1 is accepted

Sort by
0
Bruno
Top achievements
Rank 2
answered on 26 Jun 2009, 11:56 AM
I think that the problem lies in the fact that SPField does not provide a way to directly access its value through a property, this is why custom list fields are not shown event if they are stated explicitly by adding grid columns.

As a workaround you may try converting the SpList to a regular collection by iterating it and than feed the RadGrid control.
Another possible solution will be to use GetDataTable method and use Template column which to manually populate.

--Bruno
0
Shiri
Top achievements
Rank 1
answered on 28 Jun 2009, 01:22 PM
Thank you for your reply,
We havn't understood how to use the template columns solution in our case.
We'll be very gratefull if you could send us a code sample, of how to use your given solution.

In addition, we tried the solution that creates a collection with SPListItems but with no success.

Regards,
shiri
0
Bruno
Top achievements
Rank 2
answered on 30 Jun 2009, 10:12 AM
you may try creating a template column with template similar to the following:

  class MyTemplate: ITemplate
        {
            string _fieldName;
            CheckBox _checkbox;

            public MyTemplate(string fieldName)
            {
                _fieldName = fieldName;
            }           

            public void InstantiateIn(Control container)
            {
                _checkbox = new CheckBox();
                _checkbox.ID = "CheckBox1";
                container.Controls.Add(_checkbox);
                container.DataBinding += new EventHandler(container_DataBinding);
            }

            void container_DataBinding(object sender, EventArgs e)
            {
                GridDataItem gridDataItem = ((GridDataItem)((Control)sender).NamingContainer);
                string value = DataBinder.Eval(((GridDataItem)((Control)sender).NamingContainer).DataItem, fieldName).ToString();
                _checkbox.Checked = value == "1" ? true : false;
            }
        }

Note that in this case the GetDataTable method is used to populate to RadGrid control.

--Bruno
Tags
Sharepoint Integration
Asked by
Shiri
Top achievements
Rank 1
Answers by
Bruno
Top achievements
Rank 2
Shiri
Top achievements
Rank 1
Share this question
or