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

RadGrid Data Bind at client side using PageMethod

3 Answers 235 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Noha
Top achievements
Rank 1
Noha asked on 08 May 2013, 11:09 PM
Dear All

I created a page method that return the result data source in json string format to bind the RadGrid:

[WebMethod]
public static string GetRows(int from, int len)
{
    DataTable dt =  MyEntity_BL.GetData();
 
    //convert DataTable into Json string
    System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
    List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
    Dictionary<string, object> row = null;
 
    foreach (DataRow dr in dt.Rows)
    {
        row = new Dictionary<string, object>();
        foreach (DataColumn col in dt.Columns)
        {
            row.Add(col.ColumnName, dr[col]);
        }
        rows.Add(row);
    }
    return serializer.Serialize(rows);
}

and then i call the page method at client side at user button click:

function btnShowClientClick(clickedButton) {
 
    PageMethods.GetRows(0, 0, Succsess);
 
}
 
function Succsess(result) {
    var masterTable = $find("<%= grd.ClientID %>").get_masterTableView();
    masterTable.set_dataSource(result);
    masterTable.rebind();
}

The problem is that there no action done on the RadGrid ??
It doesn't bind any data!

Is there something miss ?

Thanks

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 13 May 2013, 01:37 PM
Hi Noha,

When binding RadGrid on the client, the data must have a valid JSON syntax, in order to be properly parsed. The data itself may be coming from a WebService/PageMethod, or declared statically. More information you could find in the following online documentation article:
http://www.telerik.com/help/aspnet-ajax/grid-client-side-binding-specifics.html

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
luc bonenfant
Top achievements
Rank 1
answered on 16 Sep 2015, 09:30 PM

I had the same behavior and, client side, i needed to transform string to JSON by :

    var $ = $telerik.$;
    result = $.parseJSON(result); 

I don't understand because ajax datatype ​should be JSON... may be string is particular

0
Konstantin Dikov
Telerik team
answered on 22 Sep 2015, 07:50 AM
Hello Luc,

I would suggest that you take a look at the following help article and the "dataType" part in particular, where you will find detailed information about the returned type of the request:
Hope this helps.


Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Noha
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
luc bonenfant
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or