---
title: "building dynamic table from json serialized list object"  
description: "building dynamic table from json serialized list object"  
author: "Anonymous User"  
published: 2014-09-01  
updated: 2014-09-01  
canonical: https://www.mindstick.com/forum/2215/building-dynamic-table-from-json-serialized-list-object  
category: "asp.net"  
tags: ["asp.net", ".net", "c#", "json serialized list object", "building dynamic table", "building dynamic table from json serialized list object"]  
reading_time: 2 minutes  

---

# building dynamic table from json serialized list object

I'm trying to get a serialized json list via ajax and create [dynamic table](https://www.mindstick.com/forum/34298/i-have-created-dynamic-table-in-javascript-and-how-to-save-data-in-sql-db) in a html jquery mobile page. the list comes from a [sql database](https://www.mindstick.com/articles/337535/connecting-to-sql-databases-ado-dot-net-essentials) in [code behind](https://www.mindstick.com/forum/2199/call-javascript-s-function-from-code-behind). I just don't know if I'm returing the [json object](https://www.mindstick.com/forum/699/how-to-parse-into-json-object-using-json-parse-in-node-js) right, and how to access it from the ajax success function.

My goal is to create dynamically a table of all the members in the html.

I created a Member class:

public class Member

{

public Member()

{

//

// TODO: Add constructor logic here

//

}

public String fName { set; get; }

public String lName { set; get; }

}

This is my function to return the member list in code behind: (written in a class that connects with the sql)

public List<Member> return_member_list()

{

List<Member> member_list = new List<Member>();

String fName;

String lName;

[SqlConnection](https://www.mindstick.com/forum/1209/sqlconnection-sqlcommand-sqldatareader-idisposable) user_con = connect("ActConString");

[SqlCommand](https://www.mindstick.com/forum/91/difference-between-sqlcommand-and-sqlcommandbuilder) user_command = create_command(user_con, "select m_first_name, m_last_name from member");

SqlDataReader rdr = user_command.ExecuteReader();

while (rdr.Read())

{

Member m1 = new Member();

fName = Convert.ToString(rdr["m_first_name"]);

lName = rdr["m_last_name"].ToString();

m1.fName = fName;

m1.lName = lName;

member_list.Add(m1);

}

rdr.Close();

user_con.Close();

return member_list;

}

then I use an [aspx page](https://www.mindstick.com/forum/218/how-do-i-create-an-aspx-page-that-periodically-refreshes-itself) web [method to return](https://www.mindstick.com/forum/55125/how-to-create-generic-method-to-return-multiple-list-in-c-sharp) the list serialized:

[WebMethod]

public static String return_member_list()

{

dbservices db1 = new dbservices();

List<Member> member_list = db1.return_member_list();

var jsonSerialiser = new JavaScriptSerializer();

var json = jsonSerialiser.Serialize(member_list);

return json;

}

and the ajax:

$(document).ready(function () {

$.ajax({

type: "POST",

url: "getdata.aspx/return_member_list",

data: "{}",

contentType: "[application](https://www.mindstick.com/articles/12824/calculator-application-in-android)/json; charset=utf-8",

dataType: "json",

success: function (res) {

//this is where I need help

},

error: function (res, msg, code) {

// log the error to the console

alert("The following error occured: " + msg + " " + code);

} //error

});

});

I'd appriciate help with creating the table dynamically as well

## Replies

### Reply by Sumit Kesarwani

You need to do the success function as below

success: function (res) {

var parsedData = JSON.parse(res.d);

var tableStr = "<table>";

$.each(parsedData, function(){

tableStr +="<tr><td>"+this.fName+"</td><td>"+this.lName+"</td></tr>";

});

tableStr += "</table>";

$('#tableDiv').html(tableStr);

}

Assumes that you have a div with the id tableDiv


---

Original Source: https://www.mindstick.com/forum/2215/building-dynamic-table-from-json-serialized-list-object

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
