日期:2014-05-16  浏览次数:20535 次

.net GridView控件 删除事件如何判断ID呢?
前台代码
  <div>
            <asp:GridView ID="GV" runat="server" OnRowDeleting="GV_RowDeleting" >
                <Columns>
                    <asp:CommandField ShowDeleteButton="True" />
                </Columns>
             
            </asp:GridView>
</div>

 我挺别人说这个是删除OnRowDeleting="GV_RowDeleting"事件,然后我写删除的时候有一个问题如何判断ID呢?
             var result = from r in lqDB.KC
                         where r.ID == 如何判断呢?
                         where r.ID > 0
                         select r;
            lqDB.KC.DeleteAllOnSubmit(result);
            lqDB.SubmitChanges();

------解决方案--------------------
protected void GridView1_OnRowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int id = Convert.ToInt32  ( GridView1.DataKeys[e.RowIndex].Value);//获得要删除行的id
 var result = from r in lqDB.KC
                         where r.ID == id 
                         where r.ID > 0
                         select r;
            lqDB.KC.DeleteAllOnSubmit(result);
            lqDB.SubmitChanges();
}