I'm trying to dynamically add new rows to a table using the idea marked as answer here Add table row in jQuery
I have so far implemented it for one of my table requirements like below
function onAddItem() {
$('#myDynamicTable tr:last').after('<tr><td style="width: 78%;" class="itemName"><input type="text" style="width: 97%;" /></td><td style="width: 20%;" class="itemQty"><input type="text" style="width: 87%;" /></td></tr>');
$("#myDynamicTable").show();
}
I'm now trying to implement the same for the <tr>..</tr>
definition below but i'm failing to get it working.
<tr class="tdBorder">
<td class="tdBorder">
@Html.TextBox("Id", null, new { @width = 60 })
</td>
<td>
@Html.TextBox("Name", null, new { @width = 150 })
</td>
<td>
@Html.DropDownList("ddlCountries", new SelectList(ViewBag.CountryList as System.Collections.IEnumerable, "Value", "Text"), new { @width = 60 })
</td>
<td>
@Html.TextBox("Event", null, new { @width = 60 })
</td>
<td>
@Html.DropDownList("ddlRegions", new SelectList(ViewBag.RegionList as System.Collections.IEnumerable, "Value", "Text"), new { @width = "auto" })
</td>
<td>
@Html.TextBox("Remarks", null, new { @width = 700 })
</td>
</tr>
I thought i would try the line below but that crushes jQuery.
$('#myDynamicTable tr:last').after('<tr class="tdBorder"><td class="tdBorder">@Html.TextBox("Id", null, new { @width = 60 })</td><td>@Html.TextBox("Name", null, new { @width = 150 })</td><td>@Html.DropDownList("ddlCountries", new SelectList(ViewBag.CountryList as System.Collections.IEnumerable, "Value", "Text"), new { @width = 60 })</td><td>@Html.TextBox("Event", null, new { @width = 60 })</td><td>@Html.DropDownList("ddlRegions", new SelectList(ViewBag.RegionList as System.Collections.IEnumerable, "Value", "Text"), new { @width = "auto" })</td><td>@Html.TextBox("Remarks", null, new { @width = 700 })</td></tr>');