我有一个从 SQL 数据库填充的 GridView,gridview 中的每一行都有一个更新按钮。现在我要做的是,当我单击特定行的更新按钮时,我希望我的数据库将该特定行从 active = true 设置为 active = false。我如何让我的 Linq 查询在我的数据库中选择特定的数据行并仅更新该项目?
这是我在 gridView 中创建 Button 的 asp.net 代码
<telerik:GridTemplateColumn UniqueName="TemplateUpdateColumn">
<ItemTemplate>
<asp:LinkButton ID="UpdateLink" runat="server" CommandName="Update" Text="Update" OnClientClick="return confirm('You are about to update this Incident. \nAre you sure?')"><img src="../Images/icons/Trash.png" class="images" alt="Action" style="margin-left:5px"/></asp:LinkButton><br />Delete
</ItemTemplate>
</telerik:GridTemplateColumn>
这是我的 C# 代码,它应该更新我的数据库中的特定记录。
protected void grdIncidents_UpdateCommand(object sender, GridCommandEventArgs e)
{
Context db = new Context();
var cmd = (from i in db.Incidents
where i.IncidentID == //8
select i).FirstOrDefault();
cmd.Active = false;
db.SaveChanges();
}