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

[Solved] Client-Side DataBinding problem

1 Answer 157 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lyle Groome
Top achievements
Rank 2
Lyle Groome asked on 29 Sep 2009, 05:29 PM
I am client-side binding a RadGrid and can't get it to show my results?

The JavaScript function below does get the results correctly (I know because I step into it and the results are there)
The results is a dictionary - see code behind code below...

But I can't get it to show the results in the grid??
help

JavaScript
            function updateGridCred(result) { 
                var masterTable = $find("<%= gridCred.ClientID %>").get_masterTableView(); 
                masterTable.set_virtualItemCount(result); 
                masterTable.clearSelectedItems(); 
                masterTable.set_dataSource(result); 
                masterTable.dataBind(); 
 
                $('#divCred').show(); 
            } 

RadGrid
              <telerik:RadGrid ID="gridCred" runat="server" 
                AllowSorting="true" 
                AutoGenerateColumns="false" 
                Width="381" 
                > 
                <ItemStyle Wrap="false" />  
                <MasterTableView  
                    TableLayout="Fixed" 
                    AllowAutomaticDeletes="true" 
                    EnableColumnsViewState="false" 
                    ClientDataKeyNames="CredentialOrganizationId"  
                    DataKeyNames="CredentialOrganizationId" 
                    >      
                <Columns>  
                    <telerik:GridBoundColumn DataField="OrganizationType" UniqueName="OrganizationType" HeaderText="Type"
                        <HeaderStyle Width="25px" HorizontalAlign="Center" /> 
                        <ItemStyle Width="25px" HorizontalAlign="Center" /> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="OrganizationName" UniqueName="OrganizationName" HeaderText="Organization Name" /> 
                    <telerik:GridBoundColumn DataField="DistrictName" UniqueName="DistrictName" HeaderText="District" /> 
                     
                    <telerik:GridClientDeleteColumn ConfirmText="Are you sure you want to delete the selected row?" HeaderStyle-Width="35px" ButtonType="ImageButton" /> 
                     
                </Columns>  
                </MasterTableView> 
                <ClientSettings> 
                     
                    <DataBinding  
                        EnableCaching="false" 
                        Location="UserAdmin.aspx" 
                        SelectMethod="GetCredentialsAndCount" 
                        CountPropertyName="Count"  
                        DataPropertyName="Data"  
                        StartRowIndexParameterName="startRowIndex" 
                        MaximumRowsParameterName="maximumRows"  
                        FilterParameterType="Linq" 
                        FilterParameterName="filterExpression" 
                        SortParameterType="Linq"  
                        SortParameterName="sortExpression" 
                    />  
                    <Selecting AllowRowSelect="true" /> 
                    <ClientEvents OnCommand="gridCred_OnCommand" OnRowSelected="gridCred_CredSelected" /> 
                </ClientSettings> 
            </telerik:RadGrid> 

Codebehind method
[WebMethod] 
    public static Dictionary<string, Object> GetCredentialsAndCount(int startRowIndex, int maximumRows, string sortExpression, string filterExpression, string CredentialId) 
    { 
        var page = new Apps_UserAdmin(); 
        var dc = page.PageCachedContext.DC; 
        var filter = !String.IsNullOrEmpty(filterExpression); 
        var sort = !String.IsNullOrEmpty(sortExpression); 
        var credId = CredentialId; 
 
        // have to instantiate the object because static 
        var query = (from co in dc.CredentialOrganizations 
                     join tsch in dc.Schools on co.OrganizationId equals tsch.OrganizationId 
                         into tschs 
                     from s in tschs.DefaultIfEmpty() 
                     where co.CredentialId == Convert.ToInt64(credId) 
                     orderby co.Organization.Type, s.District.Organization.Name, co.Organization.Name 
                     select new  
                     { 
                         DistrictName = s.District.Organization.Name, 
                         OrganizationType = co.Organization.Type, 
                         CredentialId = co.CredentialId, 
                         CredentialOrganizationId = co.CredentialOrganizationId, 
                         OrganizationName = co.Organization.Name, 
                         ImageType = ((PinnacleEnums.OrganizationType)Enum.ToObject(typeof(PinnacleEnums.OrganizationType), Convert.ToInt32(co.Organization.Type))).ToString(), 
                     }); 
 
        if (filter) 
        { 
            query = query.Where(filterExpression); 
        } 
        if (sort) 
        { 
            query = query.OrderBy(sortExpression); 
        } 
 
        var count = query.Count(); 
        var finalItems = query.Skip(startRowIndex).Take(maximumRows); 
 
        return new Dictionary<stringobject> { { "Data", finalItems }, { "Count", count } }; 
    } 
 

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 02 Oct 2009, 10:05 AM
Hello Lyle,

For your convenience I am attaching sample application demonstrating RadGrid client-side data-binding. Please find it attached to this post.

Kind regards,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Lyle Groome
Top achievements
Rank 2
Answers by
Nikolay Rusev
Telerik team
Share this question
or