Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

How can I return dataset from webservice to .aspx page and bind two tables in the .aspx page.


I need to use jquery ajax, json.


Please help me to do it.


Thanks in advance

Dileep
Posted
Updated 21-Aug-12 5:49am
v2
Comments
[no name] 21-Aug-12 11:45am    
http://www.codeproject.com/Articles/64628/Code-Project-Quick-Answers-FAQ

1 solution

Check the url,
http://stackoverflow.com/questions/451460/datatable-to-json[^]

http://james.newtonking.com/pages/json-net.aspx[^]

The basic idea behind this is,
1. Get all datatable objects from dataset in webservice
2. Get the JSOn string for each datatable
3. Or you can get the data into Dictionary<string,>
Here is a code to convery to JSON string
public static string GetJSONString(DataTable Dt)
{

string[] StrDc = new string[Dt.Columns.Count];
string HeadStr = string.Empty;

for (int i = 0; i < Dt.Columns.Count; i++)
{

StrDc[i] = Dt.Columns[i].Caption;

HeadStr += "\"" + StrDc[i] + "\" : \"" + StrDc[i] + i.ToString() + "¾" + "\",";
}

HeadStr = HeadStr.Substring(0, HeadStr.Length - 1);

StringBuilder Sb = new StringBuilder();
Sb.Append("{\"" + Dt.TableName + "\" : [");

for (int i = 0; i < Dt.Rows.Count; i++)
{

string TempStr = HeadStr;
Sb.Append("{");

for (int j = 0; j < Dt.Columns.Count; j++)
{

TempStr = TempStr.Replace(Dt.Columns[j] + j.ToString() + "¾", Dt.Rows[i][j].ToString());
}

Sb.Append(TempStr + "},");
}


Hope this helps.
cheers
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900