RadGrid with dynamic DataSource

2 posts, 0 answers
  1. Douglas
    Douglas avatar
    1 posts
    Member since:
    Jun 2012

    Posted 21 Feb 2012 Link to this post

    I have a RadGrid that needs to have dynamic DataSource. The grid will have an A to Z index, where only names started by selected alphabeth is displayed.

    When the grid is first loaded, the datasource is by default:

    <asp:LinqDataSource ID="ldsMember" ContextTypeName="RedBuckDataContext" TableName="RB_Members" OrderBy="FIFOType" runat="server" />

    It loads fine, I can edit, insert and delete columns with no problems.

    When an A-Z linkbutton is clicked, the grid's datasource is changed:

                    using (RedBuckDataContext rbdc = new RedBuckDataContext())
                    {
                        var member = (from m in rbdc.RB_Members
                                      where m.Name.StartsWith(lbAlp.CommandArgument)
                                      select m);

                        rgMember.DataSource = member.ToList();
                    }

            rgMember.DataSourceID = null;
            rgMember.DataBind();

    The grid displays only data starated with the selected alphabeth, which is good!

    The problem is, when I click "Edit" to modify the data, the grid does not display anything. The rows displayed were gone. It is like the datasource has been resetted.

    Can anyone please help me on this?

    Cheers,

    Andry

  2. Tsvetina
    Admin
    Tsvetina avatar
    1582 posts
    Member since:
    Sep 2012

    Posted 23 Feb 2012 Link to this post

    Hi Douglas,

    Please note that when using simple data-binding you need to assign the data source and rebind the grid after any data operation such as paging, sorting, editing, and so on.

    As a different option, you can cosider switching to using advanced data-binding to have this rebinding handled by the RadGrid control implicitly:
    http://www.telerik.com/help/aspnet-ajax/grid-advanced-data-binding.html

    Regards,
    Tsvetina
    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.

Back to Top