Pass dataview to javascript [modified]
-
hi all, this is code behind:
[System.Web.Services.WebMethod, System.Web.Script.Services.ScriptMethod()]
public static DataView getAccounts() { try { string strCon = ConfigurationManager.ConnectionStrings\["TFConnectionString"\].ToString(); SqlDataSource db = new SqlDataSource(); db.ConnectionString = strCon; db.SelectCommandType = SqlDataSourceCommandType.StoredProcedure; db.SelectCommand = "getAccounts"; db.SelectParameters.Add("loginId", "K"); DataSourceSelectArguments args = new DataSourceSelectArguments(); DataView lst = (DataView)db.Select(DataSourceSelectArguments.Empty); return lst; } catch (Exception ex) { return null; } }
and this is javascript:
function f1()
{PageMethods.getAccounts(callSuccess, callFailuer);
}
function callSuccess(result)
{alert(result[0]["account_nick"]);
}
function callFailuer()
{
alert('Fail');
}in codebehind lst [DataView] shows records but on javascript its call failuer methode why? i just want pass the data to javascript as a list. thanks
modified on Thursday, August 13, 2009 12:33 PM
-
hi all, this is code behind:
[System.Web.Services.WebMethod, System.Web.Script.Services.ScriptMethod()]
public static DataView getAccounts() { try { string strCon = ConfigurationManager.ConnectionStrings\["TFConnectionString"\].ToString(); SqlDataSource db = new SqlDataSource(); db.ConnectionString = strCon; db.SelectCommandType = SqlDataSourceCommandType.StoredProcedure; db.SelectCommand = "getAccounts"; db.SelectParameters.Add("loginId", "K"); DataSourceSelectArguments args = new DataSourceSelectArguments(); DataView lst = (DataView)db.Select(DataSourceSelectArguments.Empty); return lst; } catch (Exception ex) { return null; } }
and this is javascript:
function f1()
{PageMethods.getAccounts(callSuccess, callFailuer);
}
function callSuccess(result)
{alert(result[0]["account_nick"]);
}
function callFailuer()
{
alert('Fail');
}in codebehind lst [DataView] shows records but on javascript its call failuer methode why? i just want pass the data to javascript as a list. thanks
modified on Thursday, August 13, 2009 12:33 PM
DataView is not serialized. You need to pass XML or JSON serialized data objects through return. Rather than going like this, I recommend to use a comma separated string to pass data to the javascript function.:thumbsup::thumbsup:
Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.