Let say that we have an object
class Entity
{
public string ID {get; set;}
public string Name {get; set;}
}
I want to bind properti
Sadly to say that, but ASP.NET does not support two-way binding to .net objects... instead you can use something like "manual binding" on every post back (here AddIncomeSources is RepeaterControl)
public List AdditionalIncomeList
{
get { return ViewState["AdditionalIncome"] as List; }
set { ViewState["AdditionalIncome"] = value; }
}
foreach (RepeaterItem item in AddIncomeSources.Items)
{
var amount = (TextBox)item.Controls.Cast().First(c => c.ID == "Amount");
var document = (DropDownList)item.Controls.Cast().First(c => c.ID == "Document");
AdditionalIncomeList[item.ItemIndex].Amount = amount.Text.ToDouble();
AdditionalIncomeList[item.ItemIndex].IncomeDocument = document.SelectedValue;
}
AddIncomeSources.DataSource = AdditionalIncomeList;
AddIncomeSources.DataBind();