带有按钮字段删除和删除的 Gridview Linq 到 SQL DAL
我正在尝试在 GridView 中实现一个简单的 Button 字段。
<asp:ButtonField ButtonType="Button" CommandName="Delete" Text="Delete" />
我有一个三层应用程序,我将在本示例中将其合并为一个函数:
protected void GV1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
var deletion = (HRA_internalLesion) GV1.SelectedRow.DataItem;
DataContext conn = new DataContext();
conn.HRA_internalLesions.DeleteOnSubmit(deletion);
conn.SubmitChanges();
}
}
我确信 vardeletion
行不会返回我想要的 Linq to SQL 对象。
I'm trying implement a simple Button
field in the GridView
.
<asp:ButtonField ButtonType="Button" CommandName="Delete" Text="Delete" />
I have a three-tier application that I'll combine into one function for this example:
protected void GV1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
var deletion = (HRA_internalLesion) GV1.SelectedRow.DataItem;
DataContext conn = new DataContext();
conn.HRA_internalLesions.DeleteOnSubmit(deletion);
conn.SubmitChanges();
}
}
I'm sure the var deletion
line is not returning the Linq to SQL object I want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最初呈现控件后,
DataItem
属性不可用。如果您想执行此操作,则必须从页面上的字段重新创建数据对象。编辑:
来自MSDN:
我不知道为什么它说“以及之后”——这对我来说是令人困惑的语言——但尽管如此,还是有记录在案的证据。
The
DataItem
property isn't available after the control has been rendered initially. You'll have to re-create the data object from your fields on the page if you want to do this.Edit:
From MSDN:
I'm not sure why it says "and after" -- this is confusing language to me -- but nonetheless, there's documented evidence.