1

I have the following DataList-

<td>
<asp:Label ID="Label3" runat="server" Text="Exclude"></asp:Label>
<asp:DataList runat="server" ID="excludeTextBox">
<ItemTemplate>

<br />
<asp:TextBox ID="myTextBox" runat="server" Text='<%# Container.DataItem.ToString() %>'></asp:TextBox>&nbsp;


</ItemTemplate>
</asp:DataList>
<td>
<asp:Label ID="Label4" runat="server" Text="Active"></asp:Label>
<asp:DataList runat="server" ID="activeCheck" >

<ItemTemplate>

<br />
<asp:CheckBox ID="CheckBox1" runat="server"  Checked='<%# Container.DataItem.ToString().Equals("1") %>' OnCheckedChanged="CheckBox1_CheckedChanged" AutoPostBack="true" />


</ItemTemplate>
</asp:DataList>

</td>

So this is generating a textBox and checkBox for every row that exits in the database.

Currently there is no save action associated with the dataList, however if a user checks or unchecks one of the checkBoxes this calls a webservice and toggles the value in a data base table.

My question is, after a user has edited the text in some of the textBoxes and checked or unchecked some of the check boxes, how can I catch the changes in a save changes button. Because if the items have been dynamically created then technically they do not exist on the page. I want to do this without having a save option on ever row on the dataList.

protected void saveChanges_Click(object sender, EventArgs e)
{
     // capture all edits and call update webservice method.   
}
4

1 回答 1

1

您基本上必须构建更改的表示。因为没有通用的解决方案,所以我没有任何代码,但这里是过程:

随着项目的更改,您必须存储更改的内容。您可以将实际更改的行的索引存储在页面上的隐藏变量中,或者将更改存储在 JavaScript 对象中。单击保存更改后,您将在客户端上循环浏览这些更改,如果它们存在,则批量发送或一次发送一个。

如果您有一个隐藏字段,其值类似于0,2,5每个更改的索引,您可以轻松找到这些项目,从表单中获取值,然后将它们发送到 Web 服务。或者,您可以构建一个具有以下更改的 JavaScript 对象:

{ key: 2, checked: true, text:"My new text" }

将这些存储在一个数组中,并通过 Web 服务将它们推送到服务器。

于 2013-01-23T16:05:02.953 回答