BumbleBee
BumbleBee

Reputation: 10809

Dyanamically create a table and display data using JQuery

In my ASP.NET 4.0 application I recieve an object called GeneralQuestions from my WCF service. I need to populate the data from the object in the below shown format.

GenearlQuestions object has the following properties

OrderId
Header
QuestionContent

QuestionType (Based on this value I have to create a Dropdown or Radiobutton or Text box)

SubQuestions ( This is a property of type class which has OrderId, Header, QuestionContent, QuestionType properties. For example Question 15)

Can somebody guide me how can I accomplish this using JQuery.

Upvotes: 0

Views: 344

Answers (3)

widyakumara
widyakumara

Reputation: 1234

using only jQuery, assuming you have a <div id='formContainer'> in your html:

formContainer = $('#formContainer');

row = $('<div>', {'class':'formRow'}).appendTo(formContainer);
    $('<label>', {text:'Name', for:'inputName'}).appendTo(row);
    $('<input>', {type:'text', id:'inputName'}).appendTo(row);

row = $('<div>', {'class':'formRow'}).appendTo(formContainer);
    $('<label>', {text:'Password', for:'inputPassword'}).appendTo(row);
    $('<input>', {type:'password', id:'inputPassword'}).appendTo(row);

... and so on ...

Of course, this is not an exact answer to your question, but you get the idea.

Upvotes: 1

Skyrim
Skyrim

Reputation: 865

Another alternative which I really like is ejs templates. It has a syntax a lot more like server tags and it's a bit easier for me to use :)

Upvotes: 1

Aidiakapi
Aidiakapi

Reputation: 6249

I would look into jQuery Template.

It 'pastes' JSON into a template, like for example, your table :).

Upvotes: 1

Related Questions