c# - Getting Values from Cloned Elements -
this code http://jsfiddle.net/euyb8/
<head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title> - jsfiddle demo</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.js"></script> <link rel="stylesheet" type="text/css" href="/css/normalize.css"> <link rel="stylesheet" type="text/css" href="/css/result-light.css"> <style type="text/css"> #templaterow { display:none; } table, tr, td, th { border: solid thin black; padding: 5px; } </style> <script type="text/javascript">//<![cdata[ $(function() { //attach function click event of "add box attribute button add new row $('#addattr').click(function() { //clone template row, , events attached row , in var $newrow = $('#templaterow').clone(true); //strip ids avoid dom issues $newrow.find('*').andself().removeattr('id'); //add cloned row table before last row $('#boxtable tr:last').before($newrow); //to prevent default behavior of submitting form return false; }); //attach remove row function current , future instances of "remove row" check box $('#deleteboxrow').click(function() { //find closest parent row , remove $(this).closest('tr').remove(); }); //finally, add initial row simulating "add box attribute" click $('#addattr').click(); }); //]]> </script> </head> <body> <table id="boxtable"> <tbody><tr> <th>name</th> <th>nationality</th> <th>relationship</th> <th>date of birth</th> </tr> <tr id="templaterow"> <td> <select name="boxname" id="boxname"> <option selected="selected" value="attr1">attr1</option> <option value="attr2">attr2</option> <option value="attr3">attr3</option> </select> </td> <td> <select name="boxcomparison" id="boxcomparison"> <option selected="selected" value="=">=</option> <option value=">">></option> <option value="<"><</option> <option value="like">like</option> <option value="!=">!=</option> </select> </td> <td> <input name="boxval" id="boxval" type="text"> </td> <td> <input id="deleteboxrow" name="deleteboxrow" type="checkbox"> </td> </tr> <tr> <td colspan="4"> <input name="addattr" value="add box attribute" id="addattr" type="submit"> </td> </tr> </tbody></table> </body>
how can values of generated rows , put them in c# array?
i have solution in oppinion bit hacky. since mentioning c# assume working on asp.net application. if that's right here 1 way it:
first place invisible textbox control on page. important thing here hide css. if set visible property false wont on page , cant sore in it.
once textbox added make new jquery function adds value of rows hidden textbox control. can eiter mousedown event on 'submit'-button or can on go 'changing'-event.
the last thing have have add separators row values can split them array in c#.
the value of textbox control in end:
valuerow1|valuerow2|valuerow3
back in c# easy split value array:
string[] myarr = textbox1.text.split('|');
Comments
Post a Comment