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;
}
上面的代碼(修改了一些比特向公衆公佈)工作得很好,但是我不能確定這是否是實現我的目標的最佳途徑。我應該採取更直接的路線嗎?