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オブジェクトに保存したりできます。[変更を保存]をクリックすると、クライアントでこれらの変更をループし、存在する場合は一括または一度に1つずつ送信します。

変更された各インデックスのような値を持つ非表示フィールドがある場合は、0,2,5それらのアイテムを簡単に見つけて、フォームから値を取得し、Webサービスに送信できます。または、次のような変更が加えられたJavaScriptオブジェクトを作成することもできます。

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

これらを配列に格納し、Webサービスを介してサーバーにプッシュします。

于 2013-01-23T16:05:02.953 に答える