删除一行在数据网格视图 [英] Deleting a row in datagrid view

查看:113
本文介绍了删除一行在数据网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要删除在GridView这是在更新面板一行。但不是命令按钮,我花了一个链接按钮,得到确认消息。现在,如果我preSS确定,然后记录应删除(包括从数据库和FRM girdview)。我知道如何从数据库中删除,但不是当LinkBut​​ton的是pressed和删除记录。而且还GridView控件处于更新panel.so应该有所体现。

I want to Delete a row in the Gridview which is in the update panel . But instead of the command button ., i took a link button to get a confirmation message. Now if I press ok then the record should be deleted (both from db and frm girdview). I know how to delete from db but not when linkbutton is pressed, and deleting the record. And also the gridview is in update panel.so it should be reflected.

一个样本code是AP preciated。

A sample code is appreciated.

感谢

推荐答案

您可以使用 RowCommand GridView控件的事件,如...

you can use RowCommand event of gridview, like...

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Delete")
    {            
        e.CommandArgument  -- this return Data Key Value
//Deletion Code goes here.....
var brochureToDelete = (from b in dataContext.ArticleBrochures where b.ArticleId == ArticleId select b).FirstOrDefault(); 
if (brochureToDelete != null) 
{ 
dataContext.ArticleBrochures.DeleteOnSubmit(brochureToDelete);
dataContext.SubmitChanges(); 
bindBrochureGridView(ArticleId);
// if your gridview in updatepanel
//Call update method of UpdatePanel
//UpdatePanel.Update();
 }
}

这篇关于删除一行在数据网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆