krishnasatch
16 Aug 2007, 11:12 PM
Hi everybody
I am new to ext. I think my problem is simple but i could not figure it out. I want to load data from server with jsonview so that the Template in jsonview will load in page and data returned from server will map the template in jsonview and template be rendered in browser with json data. I'm using newtonsoft json for converting object to json string.
here is the html code:
<body>
<div id="DBcontent" style=" visibility:hidden;">
</div>
</body>
here is the ext code:
var tpl = new Ext.Template(
'<div id="wow">' +
'<img id ="wimg" src="{Imagesrc}">' +
'<div id="wname">{Name}</div>'+
'<div id="wdes">{Description}</div>'+
'</div>'
);
var moreView = new Ext.JsonView("DBcontent", tpl, {
jsonRoot: "data"
});
moreView.load({
url:"ajaxload.aspx",
text:"Loading..."
});
Here is C# class of object which is converted to json
public class Myobj
{
String name;
String imagesrc;
String desription;
public string Name {
set {
name = value;
}
get {
return name;
}
}
public string Imagesrc
{
set
{
imagesrc = value;
}
get
{
return imagesrc;
}
}
public string Description {
set {
desription = value;
}
get {
return desription;
}
}
here is the server side code ( for C#.NET)
protected void Page_Load(object sender, EventArgs e)
{
Db= new MyDB();
String msg="";
DataSet ds;
myobj=new Myobj();
ds = Db.ExecuteDataset("getdata"); // called Stored Precedure
DataRow dr = ds.Tables[0].Rows[0];
myobj.Name = dr["Name"].ToString();
myobj.Imagesrc = dr["Image"].ToString();
myobj.Description = dr["Description"].ToString();
msg = "{\"data\":[";
msg+= Newtonsoft.Json.JavaScriptConvert.SerializeObject(myobj);
msg += "]}";
Response.Write(msg);
}
The json output is
{"data":[{"Name":"Bangkok Tour","Imagesrc":"images/jessica.jpg","Description":"It was rally great"}]}
but it does not render in browser with the template...just above json text appears in browser
is this due to json format....please help me .
I am new to ext. I think my problem is simple but i could not figure it out. I want to load data from server with jsonview so that the Template in jsonview will load in page and data returned from server will map the template in jsonview and template be rendered in browser with json data. I'm using newtonsoft json for converting object to json string.
here is the html code:
<body>
<div id="DBcontent" style=" visibility:hidden;">
</div>
</body>
here is the ext code:
var tpl = new Ext.Template(
'<div id="wow">' +
'<img id ="wimg" src="{Imagesrc}">' +
'<div id="wname">{Name}</div>'+
'<div id="wdes">{Description}</div>'+
'</div>'
);
var moreView = new Ext.JsonView("DBcontent", tpl, {
jsonRoot: "data"
});
moreView.load({
url:"ajaxload.aspx",
text:"Loading..."
});
Here is C# class of object which is converted to json
public class Myobj
{
String name;
String imagesrc;
String desription;
public string Name {
set {
name = value;
}
get {
return name;
}
}
public string Imagesrc
{
set
{
imagesrc = value;
}
get
{
return imagesrc;
}
}
public string Description {
set {
desription = value;
}
get {
return desription;
}
}
here is the server side code ( for C#.NET)
protected void Page_Load(object sender, EventArgs e)
{
Db= new MyDB();
String msg="";
DataSet ds;
myobj=new Myobj();
ds = Db.ExecuteDataset("getdata"); // called Stored Precedure
DataRow dr = ds.Tables[0].Rows[0];
myobj.Name = dr["Name"].ToString();
myobj.Imagesrc = dr["Image"].ToString();
myobj.Description = dr["Description"].ToString();
msg = "{\"data\":[";
msg+= Newtonsoft.Json.JavaScriptConvert.SerializeObject(myobj);
msg += "]}";
Response.Write(msg);
}
The json output is
{"data":[{"Name":"Bangkok Tour","Imagesrc":"images/jessica.jpg","Description":"It was rally great"}]}
but it does not render in browser with the template...just above json text appears in browser
is this due to json format....please help me .