我已经搜索了这个问题,虽然它似乎是一个常见的问题,我一直无法找到我的情况的解决方案。 我有一个页面上的一行asp:表格控件。一个jQuery脚本在按钮点击时添加一个具有唯一ID的新行。我的问题是,在回发到将数据添加到数据库时,附加行在回发后不存在,只是最初的一行。 所以我的问题是我如何保存动态创建的行中的数据,以便它可以传递给代码隐藏。动态创建的表行(jQuery)不传递页面回发值
jQuery函数
function addNewRow()
{
var i = 1;
$("#<%=addRow.ClientID %>").click(function() {
$("#<%=tblAddItems.ClientID %> tr").eq(1).clone().find("input").each(function() {
$(this).attr({
'id': function (_, id) { return id + i },
'name': function (_, name) { return name + i },
'value': ''
});
// $(this).val('').attr('id', function (_, id) { return id + i });
//}).end().appendTo("#<=tblAddItems.ClientID %>");
// i++;
}).end().appendTo("#<%=tblAddItems.ClientID %>");
SearchItemNumber();
i++;
});
}
的asp.net表
<asp:Table EnableViewState="true" runat="server" ID="tblAddItems" HorizontalAlign="Center" >
<asp:TableHeaderRow BackColor="#5C9CCC" Font-Bold="True" ForeColor="White" HorizontalAlign="Center"
VerticalAlign="Middle" TableSection="TableHeader" Width="975px">
<asp:TableHeaderCell style="display:none">
<asp:Label ID="Label13" runat="server" Text="Item Id"></asp:Label>
</asp:TableHeaderCell>
<asp:TableHeaderCell >
<asp:Label ID="Label1" runat="server" Text="Item Number"></asp:Label>
</asp:TableHeaderCell>
<asp:TableHeaderCell >
<asp:Label ID="Label2" runat="server" Text="Description"></asp:Label>
</asp:TableHeaderCell>
<asp:TableHeaderCell >
<asp:Label ID="Label3" runat="server" Text="UOM"></asp:Label>
</asp:TableHeaderCell>
<asp:TableHeaderCell >
<asp:Label ID="Label4" runat="server" Text="MPN"></asp:Label>
</asp:TableHeaderCell>
<asp:TableHeaderCell >
<asp:Label ID="Label5" runat="server" Text="Average Price"></asp:Label>
</asp:TableHeaderCell>
</asp:TableHeaderRow>
<asp:TableRow TableSection="TableBody">
<asp:TableCell style="display:none">
<asp:TextBox runat="server" ID="hdnItmDet" Height="12px" Width="150px" ></asp:TextBox>
</asp:TableCell>
<asp:TableCell style="display:none">
<asp:TextBox runat="server" ID="tbItmId" Height="12px" Width="150px" ></asp:TextBox>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox runat="server" ID="tbItmNo" Height="12px" Width="150px" CssClass="autosuggestItemDetails"></asp:TextBox>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox runat="server" ID="tbDescription" Height="12px" Width="150px" ></asp:TextBox>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox runat="server" ID="tbMPN" Height="12px" Width="150px" ></asp:TextBox>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox runat="server" ID="tbUOM" Height="12px" Width="150px" ></asp:TextBox>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox runat="server" ID="tbAvPrice" Height="12px" Width="150px" ></asp:TextBox>
</asp:TableCell>
<asp:TableCell style="display:none">
<asp:TextBox runat="server" ID="hdnChanged" Height="12px" Width="150px" ></asp:TextBox>
</asp:TableCell>
<asp:TableCell style="display:none">
<asp:TextBox runat="server" ID="hdnFlag1" Height="12px" Width="150px" ></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableFooterRow TableSection="TableFooter">
<asp:TableCell ColumnSpan="1">
<button runat="server" ID="addRow" type="button">Add Row</button>
</asp:TableCell>
<asp:TableCell ColumnSpan="2">
<asp:Button ID="btnSave" runat="server" Text="Add Items to List" OnClick="btnSave_Click" />
</asp:TableCell>
</asp:TableFooterRow>
</asp:Table>
和按钮
<asp:Button ID="saveList" runat="server" Text="Save Changes to List" OnClick="saveList_Click" />
这将有助于见下表HTML,并添加了jQuery文档 – Jonesopolis
你使用webforms吗? – Becuzz
@Jonesy谢谢你的时间我用代码更新了问题。和Becuzz是的,我使用webforms。 – user2359298