protected void LinqDataSource_Inserted(object sender, LinqDataSourceStatusEventArgs e)
{
if (e.Exception == null)
{
Product newProduct = (Product)e.Result;
Literal1.Text = "The new product id is " + newProduct.ProductID;
Literal1.Visible = true;
}
else
{
LogError(e.Exception.Message);
Literal1.Text = "We are sorry. There was a problem saving the record. The administrator has been notified.";
Literal1.Visible = true;
e.ExceptionHandled = true;
}
}
起先老是在listview 的 listview1_iteminserted()里打转,搞来搞去,不得要领,后来看了国外某blog,提到需要在linqdatasource的inserted()事件里取。于是翻了MSDN,方才实践一下,确是可以。本人新手,把刚才的做法贴上来,也许是火星了。有更好的方法告诉俺。