我只想問是否可以使用Javascript克隆asp控件,因爲我發現很難添加另一行,與之前的行相同..如何使用Javascript克隆ASP.NET控件
這裏是JavaScript:
<script type="text/javascript">
function deleteRow(row) {
var i = row.parentNode.parentNode.rowIndex;
document.getElementById('POITable').deleteRow(i);
}
function myFunction()
{
var table = document.getElementById("POITable");
var row = table.insertRow(2);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
var cell6 = row.insertCell(5);
cell1.innerHTML = row.cells[1].getElementsByTagName('#asp:DropDownList')[0];
cell2.innerHTML = row.cells[2].getElementsByTagName('#asp:DropDownList')[0];
cell3.innerHTML = row.cells[3].getElementsByTagName('#asp:TextBox')[0];
cell4.innerHTML = row.cells[4].getElementsByTagName('#asp:TextBox')[0];
cell5.innerHTML = row.cells[5].getElementsByTagName('#asp:TextBox')[0];
cell6.innerHTML = row.cells[6].getElementsByTagName('#asp:Label')[0];
}
</script>
這裏是表,其中我要克隆行:
<div id="POItablediv">
<table class="table" id="POITable">
<tr class="th">
<td>Fabric</td>
<td>Color</td>
<td>Good For How Many</td>
<td>Consumption</td>
<td>Allowance</td>
<td>MRP Quantity</td>
</tr>
<tr>
<td> <asp:DropDownList ID="ddlFab" runat="server" DataSourceID="DSFabric"
DataTextField="Description" DataValueField="Description" Width="120px">
</asp:DropDownList></td>
<td><asp:DropDownList ID="ddlColor" runat="server" DataSourceID="ddlColors"
DataTextField="Description" DataValueField="Description" Width="120px">
</asp:DropDownList></td>
<td><asp:TextBox ID="txtGdForHwMany" runat="server" Width="120px"
ontextchanged="txtGdForHwMany_TextChanged" ></asp:TextBox></td>
<td><asp:TextBox ID="txtConsump" runat="server" Width="120px"
ontextchanged="txtConsump_TextChanged"></asp:TextBox></td>
<td><asp:TextBox ID="txtAllow" runat="server" Width="120px"
ontextchanged="txtAllow_TextChanged"></asp:TextBox></td>
<td><asp:Label ID="lblMRPQuantity" runat="server" Text="0" Width="120px"></asp:Label></td>
<td><input type="button" id="delPOIbutton" value="Delete" onclick="deleteRow(this)"/></td>
<td><input type="button" id="addmorePOIbutton" value="Add More POIs" onclick="myFunction()"/></td>
</tr>
</table>
</div>
的DropDownList
是databounded。
有沒有什麼辦法,我可以在表中添加新行,我可以繼承我的表中的ASP控制? – jelliaes