我正在使用jquery-datatables库对我的c# asp.net项目进行分页。当我尝试保存数据时,它仅保存当前页面的数据并丢失所有其他页面的数据。桌子放在转发器内。
我该怎么做才能解决这个问题?请提出解决方案。
ASPX HTML部分:
<asp:Repeater ID="rptData" runat="server">
<HeaderTemplate>
<table class="table table-striped table-bordered table-hover dataTables-example">
<thead>
<tr>
<th style="display: none;">ID</th>
<th>Period</th>
<th>Period Date</th>
<th>Account</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr class="gradeX">
<td style="display: none;">
<asp:Literal ID="litID" runat="server"></asp:Literal>
</td>
<td>
<asp:Literal ID="litPeriod" runat="server"></asp:Literal>
</td>
<td>
<asp:Literal ID="litPeriodDate" runat="server"></asp:Literal>
</td>
<td>
<asp:Literal ID="litAccount" runat="server"></asp:Literal>
</td>
<td>
<asp:TextBox ID="txtAmount" CssClass="form-control btn-rounded" runat="server"></asp:TextBox>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
服务器端代码C#:
private void SaveTableData(string BudgetID) {
System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture;
foreach(RepeaterItem row in rptData.Items) {
Literal litID = (Literal) row.FindControl("litID");
Literal litPeriod = (Literal) row.FindControl("litPeriod");
Literal litPeriodDate = (Literal) row.FindControl("litPeriodDate");
Literal litAccount = (Literal) row.FindControl("litAccount");
TextBox txtAmount = (TextBox) row.FindControl("txtAmount");
DOL.Budget objBudget = new DOL.Budget();
objBudget.ID = Convert.ToInt32(litID.Text);
objBudget.BudgetID = BudgetID;
objBudget.AccountNumber = litAccount.Text;
objBudget.Period = litPeriod.Text;
objBudget.PeriodDate = DateTime.ParseExact(litPeriodDate.Text, "dd/MM/yyyy", provider);
objBudget.Amount = Resources.Helper.ValToDecimal(txtAmount.Text);
BAL.Budget.Insert_Details(objBudget);
}
}