Client-side binding fails
Hello
I have to build a custom control n a web page; i must show a list of archeological sites (ID, Name, site responsible, lat/lon and so on) in a grid view.
The radgrid is controlled by a web service; i have followed on-line samples, but something is wrong
Here is the code on the ascx:
<telerik:RadScriptManager ID=
"RadScriptManager1"
runat=
"server"
/>
<div style=
"width:900px;margin: auto;"
></div>
<div id=
"gmap"
style=
"width:900px; height:600px; margin: auto;"
></div>
<div id=
"divLista"
>
<telerik:RadAjaxManager ID=
"RadAjaxManager1"
runat=
"server"
>
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID=
"siteGrid"
>
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID=
"siteGrid"
/>
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadGrid ID=
"siteGrid"
runat=
"server"
AutoGenerateColumns=
"False"
Width=
"750px"
AllowPaging=
"True"
CellSpacing=
"0"
GridLines=
"None"
Skin=
"Default"
AllowFilteringByColumn=
"True"
EnableLinqExpressions=
"false"
>
<PagerStyle Mode=
"NextPrevAndNumeric"
/>
<GroupingSettings CaseSensitive=
"false"
/>
<MasterTableView TableLayout=
"Fixed"
>
<Columns>
<telerik:GridBoundColumn HeaderText=
"Site code"
DataField=
"site"
CurrentFilterFunction=
"Contains"
ShowFilterIcon=
"false"
AutoPostBackOnFilter=
"true"
></telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText=
"Site name"
DataField=
"NAME"
></telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText=
"Responsible"
DataField=
"site_responsible"
></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings>
<DataBinding Location=
"~/GService.asmx"
SelectMethod=
"getGridData"
></DataBinding>
</ClientSettings>
</telerik:RadGrid>
[WebMethod(EnableSession =
true
)]
public
List<mySite> getGridData(
int
startRowIndex,
int
maximumRows, List<GridSortExpression> sortExpression, List<GridFilterExpression> filterExpression)
gridList =
new
List<mySite>();
//string sqlSelect = "SELECT id, site, [site responsible] as site_responsible, name, ecosystem, nlat, nlon from tcdc.dbo.sites where hide=0 order by site";
string
sqlSelect =
"SELECT id, site, name,[site responsible] as site_responsible from sites where hide=0 order by site"
;
SqlConnection sqlConn =
new
SqlConnection(connection);
sqlConn.Open();
SqlCommand cmd =
new
SqlCommand(sqlSelect, sqlConn);
SqlDataReader rd = cmd.ExecuteReader();
while
(rd.Read())
try
int
ii =
int
.Parse(rd[
"id"
].ToString());
string
st = rd[
"site"
].ToString();
string
nm = rd[
"name"
].ToString();
string
rr = rd[
"site_responsible"
].ToString();
string
eco =
""
;
// rd["ecosystem"].ToString();
float
la = 0;
//float.Parse(rd["nlat"].ToString().Replace(',', '.'));
float
lo = 0;
// float.Parse(rd["nlon"].ToString().Replace(',', '.'));
mySite app =
new
mySite(ii, st, rr, nm, eco , lo, la);
gridList.Add(app);
catch
(Exception e)
rd.Close();
rd.Dispose();
sqlConn.Close();
sqlConn.Dispose();
return
gridList;
Hi Diego,
Can you check for any errors in the service or in the client-script on your page by inspecting it with Firebug? I suppose the service passes successfully, but can you also check that in the NET tab of Firebug? You can also test the grid directly on an .aspx page (too see if it behaves the same way when on a Sitefinity page and when on a regular .aspx page).
All the best,Hi Svetoslav
Unfortunately, the problem is present even in a separate aspx page
I have watched into Firebug responses and effectively the service passes and returns data
I attach 3 pics with the result I gain: response.jpg is a snapshot of the returning data by the service
map.jpg is the google map correctly populated and radgrid.jpg shows the grid desolately empty
I have just posted the code...
Thanks for your reply
Best regards
Diego
Hello svetoslav
I still have not found a solution to the problem I encountered with a radgrid and a web service.
As i wrote, the service returns the data but they are not shown in the grid.
please, i need help because it is an important sevice we have to supply to our members
Best regards
Diego
Hi Diego,
I went through your code, also I looked at the response image and noticed that DataField values you set for the columns are not included in the data returned from your WebService. Note that as DataField of the columns you should set properties of mySite object. Double check if you set proper data for your columns, correct it if needed and see if it the grid is still empty.
I recommend that you check this online example which handles a similar implementation and see if it helps. If the problem persists you could send us the code related to mySite object.
I hope this helps.
Regards,
Pavlina
the Telerik team
Hi Pavlina
Thank you for your reply
I have seen the sample code and followed your instructions; in effects, the grid is now filled, but there is another problem: it doesn't page...
Here is the result: http://193.205.144.253/home/sites-list
I made some changes in my code
This is the .ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="homeSites.ascx.cs" Inherits="SitefinityWebApp.EcoControls.homeSites" %>
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
src
=
"http://maps.googleapis.com/maps/api/js?sensor=false"
></
script
>
<
script
type
=
"text/javascript"
src
=
"http://maps.googleapis.com/maps/api/js?sensor=false"
></
script
>
<
script
type
=
"text/javascript"
>
//<
asp:TextBox
ID
=
"ecoFilter"
runat
=
"server"
onkeyup
=
'getSiteList(this.value);'
Width
=
"100px"
></
asp:TextBox
><
img
alt
=
''
src
=
"../Images/imbuto.png"
class
=
"imb"
/>
var prefix = "ctl00_Content_usercontrols_data_siteshomel_ascx1_";
var obj = [];
var lastI = 0;
var map;
var sDesc = new Array();
var marker = new Array();
var latlngArray = new Array();
</
script
>
</
telerik:RadCodeBlock
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
<
Services
><
asp:ServiceReference
Path
=
"~/GService.asmx"
/></
Services
>
</
telerik:RadScriptManager
>
<
div
style
=
"width:900px;margin: auto;"
></
div
>
<
div
id
=
"gmap"
style
=
"width:900px; height:600px; margin: auto;"
></
div
>
<
div
id
=
"divLista"
>
<
telerik:RadGrid
ID
=
"sitesGrid"
runat
=
"server"
AllowPaging
=
"true"
AllowSorting
=
"true"
AllowFilteringByColumn
=
"true"
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
<
GroupingSettings
CaseSensitive
=
"false"
/>
<
MasterTableView
TableLayout
=
"Fixed"
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
<
Columns
>
<
telerik:GridBoundColumn
HeaderText
=
"Site code"
DataField
=
"Code"
CurrentFilterFunction
=
"Contains"
ShowFilterIcon
=
"true"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
HeaderText
=
"Site name"
DataField
=
"Name"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
HeaderText
=
"Responsible"
DataField
=
"Resp"
></
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
>
<
DataBinding
SelectMethod
=
"getGridData"
Location
=
"../GService.asmx"
></
DataBinding
>
</
ClientSettings
>
</
telerik:RadGrid
>
<
table
id
=
"tabLista"
>
</
table
>
</
div
>
[WebMethod(EnableSession = true)]
public List<
mySite
> getGridData()//int startRowIndex, int maximumRows, List<
GridSortExpression
> sortExpression, List<
GridFilterExpression
> filterExpression
gridList = new List<
mySite
>();
//string sqlSelect = "SELECT id, site, [site responsible] as site_responsible, name, ecosystem, nlat, nlon from tcdc.dbo.sites where hide=0 order by site";
string sqlSelect = "SELECT id, site, name,[site responsible] as site_responsible from tcdc.dbo.sites where hide=0 order by site";
SqlConnection sqlConn = new SqlConnection(connection);
sqlConn.Open();
SqlCommand cmd = new SqlCommand(sqlSelect, sqlConn);
SqlDataReader rd = cmd.ExecuteReader();
while (rd.Read())
try
int ii = int.Parse(rd["id"].ToString());
string st = rd["site"].ToString();
string nm = rd["name"].ToString();
string rr = rd["site_responsible"].ToString();
string eco = "";// rd["ecosystem"].ToString();
float la = 0;//float.Parse(rd["nlat"].ToString().Replace(',', '.'));
float lo = 0;// float.Parse(rd["nlon"].ToString().Replace(',', '.'));
mySite app = new mySite(ii, st, rr, nm, eco , lo, la);
gridList.Add(app);
catch (Exception e)
rd.Close();
rd.Dispose();
sqlConn.Close();
sqlConn.Dispose();
return gridList;
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
namespace SitefinityWebApp
public class mySite
private int siteID = 0;
private string code = "";
private string resp = "";
private string name = "";
private string image = "";
private string igbp = "";
private float longitude = 0;
private float latitude = 0;
private List<
int
> prj;
public List<
Project
> lPr;
public List<
Flux
> lFlux;
public mySite(int ii, string cc, string rr, string nn, string eco, float lon, float lat)
//
// TODO: aggiungere qui la logica del costruttore
//
this.siteID = ii;
this.resp = rr;
this.code = cc;
this.name = nn;
this.igbp = eco;
this.longitude = lon;
this.latitude = lat;
this.prj = new List<
int
>();
this.lPr = new List<
Project
>();
this.lFlux = new List<
Flux
>();
public int ID
get return siteID;
public string Code
get return code;
public string Name
get return name;
public string Resp
get return resp;
public string Igbp
get return igbp;
public float Longitude
get return longitude;
public float Latitude
get return latitude;
public string Image
get return image;
set image = value;