1. Get DataSet
2. Convert to DataTable
3.
public static string DataTableToJson(DataTable dt)
{
StringBuilder jsonBuilder = new StringBuilder();
//jsonBuilder.Append("{"); //No output requirements'} '
//jsonBuilder.Append(dt.TableName);
jsonBuilder.Append("[");
for (int i = 0; i < dt.Rows.Count; i )
{
jsonBuilder.Append("{");
for (int j = 0; j < dt.Columns.Count; j )
{
jsonBuilder.Append(""") ;
jsonBuilder.Append(dt.Columns[j].ColumnName);
jsonBuilder.Append("":"");
jsonBuilder.Append(dt.Rows[i][j].ToString ());
jsonBuilder.Append("",");
}
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("},");
}
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("]");
//jsonBuilder.Append("}"); //Output Request not to '}'
return jsonBuilder.ToString();
}
4. Response the Json string
5. Get the Json string
function load() / /Page loading
{
$.ajax({
type:"post",
url:"../Handler/LinkManHandler.ashx",//Where to get Json
data :"action=getLinkMan&id=" comId,//Parameters passed by Ajax
beforeSend:function(){
//Display loading or loading before getting
},
success:function(mess)
{
$("#divImage").hide();
if(mess!="]")// If the obtained data is not empty
{
var type=eval(mess);
var str="
Homepage"
for(var i=0;i
{
//Operation type to get things
str ="" type[i].Database field name"
}
$("#divLinkMan"). html(str);//Embed str in div divLinkMan
}
else
{
var notfind="No data foundreturn
"
$("#divLinkMan").html(notfind);
}
},
complete:function()
{
//Method after all executions
}
});
}