Telerik
Skip Navigation LinksHome / Community / Forums / SharePoint 2007 (MOSS) > Integrating Controls > Bind SPList to RadGrid

Not answered Bind SPList to RadGrid

Feed from this thread
  • Shiri avatar

    Posted on Jun 24, 2009 (permalink)

    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.

    Reply

  • Posted on Jun 26, 2009 (permalink)

    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

    Reply

  • Shiri avatar

    Posted on Jun 28, 2009 (permalink)

    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

    Reply

  • Posted on Jun 30, 2009 (permalink)

    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

    Reply

Back to Top

Skip Navigation LinksHome / Community / Forums / SharePoint 2007 (MOSS) > Integrating Controls > Bind SPList to RadGrid

Powered by Sitefinity ASP.NET CMS

Contact Us | Site Feedback | Terms of Use | Privacy Policy
Copyright © 2002-2010 Telerik. All rights reserved.