使用DyanamicData,我有一个标准的多对多表,它在插入一个新的唯一行时工作得非常好。两个父表的dropdownlists都按其应有的方式显示,并且正确插入了行。
但是,在一个表上,我有一个唯一的索引,它抛出一个异常,我可以在OnInserted事件处理程序中捕获该异常。然后我可以向用户发回一条友好的消息,告诉他们这个问题。出现此问题的原因是DetailsView将丢失viewstate,并且用户为DropDownList选择的值将重置回页面的默认值。
protected void DetailsDataSource_Inserted(object sender, LinqDataSourceStatusEventArgs e)
{
if (e.Exception != null && !e.ExceptionHandled)
{
msgPanel.Text = "Error Occurred"; // or some other friendly message
e.ExceptionHandled = true;
// e.Result == null, so I can't rebuild the user's input from here.
// What can be put where to get the user's input restored?
}
}