我有一个从SQL数据库填充GridView中选择更新按钮更新从SQL数据库中的特定记录,在GridView的每一行,然后中有一个更新按钮。现在我所要做的是,当我在一个特定的行,我想我的数据库来设置特定行从活动= true来激活=假的更新按钮点击。我如何让我的Linq查询选择我的数据库中的特定数据行并只更新该项目?从一个GridView
下面是创建我的按钮在GridView
<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#代码我的asp.net代码。
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();
}
变种CMD = db.Incidents.FirstOrDefault(X => x.IncidentID ==/*您的值* /); 这不会工作,我需要在GridView知道哪些incidentID我指当我点击删除按钮。 因此,这段代码应该看起来像这样即时猜测 其中i.IncidentID == GridView中的记录的当前ID – user2285916 2013-04-27 15:06:17
cmd.Active = false之后;尝试Context.Entry(cmd.Active).STATE = EntityState.Modified不工作要么VS犯规知道什么Context.Entry是 – user2285916 2013-04-27 15:09:13
什么是父类“上下文”的?我假设它是DbContext或其他实体框架上下文。另外,在你的问题中,你不要指定你的代码运行时得到的结果。你能否添加这些信息? – 2013-05-01 03:01:41