After postback (click on a button) in my ASP.NET form, all the DataItem of my form are null. Why? What should I do to retrieve the content of the DataList even after postback?
protected void buttonAddRecord_Click(object sender, EventArgs e)
{
foreach (DataListItem item in listFields.Items)
{
// item.DataItem == null WTF?
}
}
protected void Page_Load(object sender, EventArgs e)
{
BindFields();
}
private void BindFields()
{
object setting = MySettings.GetSetting();
if (!Null.IsNull(setting))
{
listFields.DataSource =
DataProvider.GetData(int.Parse(setting.ToString()));
listFields.DataBind();
}
listFields.Visible = listFields.Items.Count > 0;
emptyMessage.Visible = listFields.Items.Count == 0;
}