Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here the dropdownlist is getting binded and functionality is working fine but i am facing problem in creating dynamic dropdownlist on click of an anchor tag and i should get the same dropdwonlist which is as of before which is already present in a page dropdwonlist....pls help me soon

cshtml:
XML
<table class="table-hover table12">
                                      <thead>
                                          <tr>
                                              <td class="timezone1">
                                                  <strong>Holiday Names</strong>
                                              </td>
                                              <td class="timezone1">
                                                  <strong>Dates</strong>
                                              </td>
                                          </tr>
                                      </thead>
                                      <tr class="BindDDLClass">
                                          <td class="BindDDL">

                                              @Html.DropDownList("HolidayId", new SelectList(Model.HolidayList.ToList(), "PkHolidayDateId", "HolidayName"), "--Select--")
                                          </td>
                                          <td class="BindTxt">
                                              <input type="text" class="datetext" id="datetxts" /></td>
                                      </tr>



button:
HTML
<a href="#" id="BtnAdd" class="table12" önclick="return false">AddHoliday</a>

jquery:
JavaScript
$(document).ready(function () {
 $(".table12").live('click', function () {
        $(this).append('<tr class="BindDDLClass"><td class="BindDDL">' + '<select>$("#HolidayId")</select>' +
              '$("#datetxts")' +
             
            '</td></tr>')
});
});
Posted
v2

1 solution

You can refer below code snippet, which adds new row to a table by copying existing row html.

<html>
<head>
    <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
</head>
<body>
    <table id="mainTbl" class="table-hover table12">
        <thead>
            <tr>
                <td class="timezone1">
                    Holiday Names
                </td>
                <td class="timezone1">
                    Dates
                </td>
            </tr>
        </thead>
        <tr class="BindDDLClass">
            <td class="BindDDL">
                <select id="select1">
                    <option>1</option>
                    <option>2</option>
                </select>
            </td>
            <td class="BindTxt">
                <input type="text" class="datetext" id="datetxts" />
            </td>
        </tr>
    </table>
    <a href="#" id="BtnAdd" class="table12" onclick="return false">AddHoliday</a>
    <script>
        $(document).ready(function () {
            $("#BtnAdd").on('click', function () {
                var trHtml = $('.BindDDLClass').html();
                $('#mainTbl').append("<table><tbody><tr>" + trHtml + "</tr></tbody></table>");
            });
        });
    </script>
</body>
</html>
 
Share this answer
 
Comments
Member 10028392 12-Jan-14 4:49am    
Here the jquery is working fine but for the textbox i had written a jquery for datepicker as like when the dropdown and textbox is created dynamically , the textbox is not working properly i.e when clicked the datepicker is not showing pls help.
Mahesh Bailwal 12-Jan-14 8:18am    
Please post your Jquery code for datepicker.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900