Creating rows dynamically on client side and saving them to database on server side

Hi,

I have a asp.net site and my question is if it's possible to create rows dynamically like in a table on the client side with javascript or jquery and then loop through that set of rows on server side and save the entered content to the database.

For example I have a row with a dropdown and a textbox, and I want the user to dynamically create rows on the client side, enter content to the dropdown and the textbox for each row and then when they hit save iterate through this table and save each row to the database.

How can I achieve this?

Peter
Peter NordbergIT ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KNVB HKSITOCommented:
You can create the following form:
<form action=[i]your server side script[/i]>
    <table id=dataEntry>
        <tr>
         <td><select name=select1><option value=1>One</option></select></td>
         <td><input type=text1></td>
         <td><input type=button value="Add row" onclick="addRow()"></td>
         </tr>
</table>
<input type=hidden name=count>
</form>

Open in new window


For the function "addRow()", you may refere the following web page:

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/Q_28373610.html#a39885044

Don't forget to handle the form field named count, you need this data to indicate the no. of rows that user have been added.

Good Luck
0
Big MontyWeb Ninja at largeCommented:
why build the logic from scratch when there are plenty of objets already created, both client side and server side?

you could use .NET's built-in GridView control, which is server side, or you could use something like jqGrid or FlexiGrid for client side functionality (they both will allow you to load/save data from the server as well.

I disagree @cstsang's suggestion of manually building out the logic of these types or tables/grids, especially with so many controls out there that have already been written and tested.
0
OriNetworksCommented:
I agree with using an existing component if that's a possible option. I also found myself in a situation where I had to recreate this from scratch so here's what i did.

I have a regular html table that the user builds using fields on the page and javascript/jQuery. When the user adds rows to this table then clicks the save button, it converts the table into a javascript object array and builds a json string for a hidden asp:TextBox control. On the server end I grab the value of that textbox and deserialize it using the deserialize method of System.Web.Script.Serialization.JavaScriptSerializer which populates a list of a custom object . VB.Net Example:  
Public Class Person
Public FirstName As String = ""
Public LastName As String = ""
End Class

Open in new window


Then I can deserialize the json using
Dim jss As New JavaScriptSerializer()
Dim ListOfPeople As List(Of Person)
ListOfPeople = jss.Deserialize(Of List(Of Person))(txtJsonFromForm.Text)

Open in new window


Using this new ListOfPeople object I can iterate over the list to add to the database as needed. In this case of course the property names FirstName and LastName match the json that I am building on the client side of the page.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Peter NordbergIT ManagerAuthor Commented:
All Solutions have me an idea on how to do it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.