0
作成したオブジェクトの一般的なリストにバインドされたListViewがあります。オブジェクトの一般的なリストをListViewにバインドし、バインドされたリストを更新します。
<asp:ListView ID="lvwConfig" runat="server">
<ItemTemplate>
<br />
<div class="title_small">
<asp:Label ID="lblName" runat="server" Text='<%#Eval("Name")%>'/>
</div>
<asp:TextBox ID="iFirstValue" runat="server" MaxLength="8" Text='<%#Eval("FirstValue")%>'></asp:TextBox><br />
<asp:TextBox ID="iSecondValue" runat="server" MaxLength="8" Text='<%#Eval("SecondValue")%>'></asp:TextBox><br />
<asp:TextBox ID="iThirdValue" runat="server" MaxLength="8" Text='<%#Eval("ThirdValue")%>'></asp:TextBox><br />
</ItemTemplate>
</asp:ListView>
protected void btnSave_Click(object sender, EventArgs e)
{
//Loop through each item in the listview
for (int i = 0; i < lvwSMSConfig.Items.Count(); i++)
{
//Some code to check to see if the value was updated
//If it was, call UpdateItem
lvwSMSConfig.UpdateItem(i,true);
}
}
protected void lvwSMSConfig_ItemUpdating(Object sender, ListViewUpdateEventArgs e)
{
TextBox iFirstValue= (TextBox)lvwSMSConfig.Items[e.ItemIndex].FindControl("iFirstValue");
TextBox iSecondValue= (TextBox)lvwSMSConfig.Items[e.ItemIndex].FindControl("iSecondValue");
TextBox iThirdValue= (TextBox)lvwSMSConfig.Items[e.ItemIndex].FindControl("iThirdValue");
myObjectList[e.ItemIndex].FirstValue= iFirstValue.Text;
myObjectList[e.ItemIndex].SecondValue= iSecondValue.Text;
myObjectList[e.ItemIndex].ThirdValue= iThirdValue.Text;
}
上記のコード(公衆投稿のためのいくつかのビットを変更)が正常に動作します、これは私の目標を達成するための最良の方法である場合には、しかし、私はわかりませんよ。私が取るべきより直接的な迂回はありますか?